खोज…


सिस्टम एल एंड एफ का उपयोग करना

स्विंग काफी कुछ देशी एल एंड एफएस का समर्थन करता है।
आप हमेशा एक विशिष्ट एल एंड एफ वर्ग के लिए कॉल किए बिना आसानी से स्थापित कर सकते हैं:

public class SystemLookAndFeel
{
    public static void main ( final String[] args )
    {
        // L&F installation should be performed within EDT (Event Dispatch Thread)
        // This is important to avoid any UI issues, exceptions or even deadlocks
        SwingUtilities.invokeLater ( new Runnable ()
        {
            @Override
            public void run ()
            {
                // Process of L&F installation might throw multiple exceptions
                // It is always up to you whether to handle or ignore them
                // In most common cases you would never encounter any of those
                try
                {
                    // Installing native L&F as a current application L&F
                    // We do not know what exactly L&F class is, it is provided by the UIManager
                    UIManager.setLookAndFeel ( UIManager.getSystemLookAndFeelClassName () );
                }
                catch ( final ClassNotFoundException e )
                {
                    // L&F class was not found
                    e.printStackTrace ();
                }
                catch ( final InstantiationException e )
                {
                    // Exception while instantiating L&F class
                    e.printStackTrace ();
                }
                catch ( final IllegalAccessException e )
                {
                    // Class or initializer isn't accessible
                    e.printStackTrace ();
                }
                catch ( final UnsupportedLookAndFeelException e )
                {
                    // L&F is not supported on the current system
                    e.printStackTrace ();
                }

                // Now we can create some natively-looking UI
                // This is just a small sample frame with a single button on it
                final JFrame frame = new JFrame ();
                final JPanel content = new JPanel ( new FlowLayout () );
                content.setBorder ( BorderFactory.createEmptyBorder ( 50, 50, 50, 50 ) );
                content.add ( new JButton ( "Native-looking button" ) );
                frame.setContentPane ( content );
                frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE );
                frame.pack ();
                frame.setLocationRelativeTo ( null );
                frame.setVisible ( true );
            }
        } );
    }
}

ये मूल L & Fs JDK सपोर्ट (OS -> L & F) हैं:

ओएस एल एंड एफ नाम एल एंड एफ वर्ग
जीटीके + के साथ सोलारिस, लिनक्स जीटीके + com.sun.java.swing.plaf.gtk.GTKLookAndFeel
अन्य सोलारिस, लिनक्स मूल भाव com.sun.java.swing.plaf.motif.MotifLookAndFeel
क्लासिक विंडोज खिड़कियाँ com.sun.java.swing.plaf.windows.WindowsLookAndFeel
विंडोज एक्स पी विंडोज एक्स पी com.sun.java.swing.plaf.windows.WindowsLookAndFeel
विंडोज विस्टा विंडोज विस्टा com.sun.java.swing.plaf.windows.WindowsLookAndFeel
लबादा लबादा com.apple.laf.AquaLookAndFeel *
आईबीएम यूनिक्स आईबीएम javax.swing.plaf.synth.SynthLookAndFeel *
एचपी यूएक्स हिमाचल प्रदेश javax.swing.plaf.synth.SynthLookAndFeel *

* ये L & Fs सिस्टम वेंडर द्वारा सप्लाई किए जाते हैं और वास्तविक L & F क्लास का नाम अलग-अलग हो सकता है

कस्टम एल एंड एफ का उपयोग करना

public class CustomLookAndFeel
{
    public static void main ( final String[] args )
    {
        // L&F installation should be performed within EDT (Event Dispatch Thread)
        // This is important to avoid any UI issues, exceptions or even deadlocks
        SwingUtilities.invokeLater ( new Runnable ()
        {
            @Override
            public void run ()
            {
                // Process of L&F installation might throw multiple exceptions
                // It is always up to you whether to handle or ignore them
                // In most common cases you would never encounter any of those
                try
                {
                    // Installing custom L&F as a current application L&F
                    UIManager.setLookAndFeel ( "javax.swing.plaf.metal.MetalLookAndFeel" );
                }
                catch ( final ClassNotFoundException e )
                {
                    // L&F class was not found
                    e.printStackTrace ();
                }
                catch ( final InstantiationException e )
                {
                    // Exception while instantiating L&F class
                    e.printStackTrace ();
                }
                catch ( final IllegalAccessException e )
                {
                    // Class or initializer isn't accessible
                    e.printStackTrace ();
                }
                catch ( final UnsupportedLookAndFeelException e )
                {
                    // L&F is not supported on the current system
                    e.printStackTrace ();
                }

                // Now we can create some pretty-looking UI
                // This is just a small sample frame with a single button on it
                final JFrame frame = new JFrame ();
                final JPanel content = new JPanel ( new FlowLayout () );
                content.setBorder ( BorderFactory.createEmptyBorder ( 50, 50, 50, 50 ) );
                content.add ( new JButton ( "Metal button" ) );
                frame.setContentPane ( content );
                frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE );
                frame.pack ();
                frame.setLocationRelativeTo ( null );
                frame.setVisible ( true );
            }
        } );
    }
}

आप इस विषय में उपलब्ध स्विंग L & Fs की एक विशाल सूची पा सकते हैं: जावा लुक एंड फील (L & F)
ध्यान रखें कि इस बिंदु पर कुछ L & Fs काफी पुराने हो सकते हैं।



Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow