Can I apply the appearance of a system to just one control?

In my Swing app, I use Substance look in my frames. But for design purposes, I want to show one JButton with the look of the system. I see that I can apply a specific user interface, for example:

myButton.setUI( new javax.swing.plaf.metal.MetalButtonUI() ); 

But is it possible to apply the default system interface to this button?

+4
source share
2 answers

The solution creates an instance of LookAndFeel by default (which should never be executed according to Javadocs). You can then get the default user interface from LaF and apply it to your button.

If this code was tested in my own application, which also uses the substance, and it worked:

 LookAndFeel laf = null; try { String lafClassName = UIManager.getSystemLookAndFeelClassName(); laf = (LookAndFeel) (Class.forName(lafClassName).newInstance()); } catch (ClassNotFoundException ex) { } catch (InstantiationException ex) { } catch (IllegalAccessException ex) { } if (laf != null) { laf.initialize(); button.setUI((ButtonUI) laf.getDefaults().getUI(button)); } 

If you want to switch between different substances, you can use SKIN_PROPERTY .

+3
source

myButton.setUI((ButtonUI)UIManager.getUI(myButton)) ?

-3
source

Source: https://habr.com/ru/post/1344256/


All Articles