开发者

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))?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜