Can I apply the system look and feel on one control only?
In my Swing application I am using a Substance look and feel in my frames. But for design purposes I want to show one JButton with the native system look and feel. I see I can apply a specific UI like:
myButton.setUI( new javax.swing.plaf.met开发者_如何学JAVAal.MetalButtonUI() );
But can I apply the default system UI to this button?
The solution is instantiating the default LookAndFeel on your own (Which should never be done according to the Javadocs). Then you can get the UI from the default LaF and apply it to your button.
If tested this code within my own application, which also uses 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 Substance skin, you can use SKIN_PROPERTY.
myButton.setUI((ButtonUI)UIManager.getUI(myButton))
?
精彩评论