| [程序开发]java中有关界面格式 sharerc 发布于 2006-05-31 13:23 | |
我先说说在JBUILDER中将程序外观变的更酷的办法! JAVA程序默认的外观(LOOKANDFEEL)可以改变为JAVA外观、MOTIF外观、WINDOWS外观、MAC外观; 而JAVA外观又有五种风格分别是海蓝宝石风格、祖母绿风格、红宝石风格、木炭风格、 高对比风格。 外观改变具体方法如下: 1:可以直接在程序中调用下面三个中的一个:
import
javax.swing.
*
; UIManager.setLookAndFeel(
"
com.sun.java.swing.plaf.motif.MotifLookAndFeel
"
); UIManager.setLookAndFeel(
"
javax.swing.plaf.metal.MetalLookAndFeel
"
); UIManager.setLookAndFeel(
"
com.sun.java.swing.plaf.windows.WindowsLookAndFeel
"
);
2:或采用菜单来变换:
import
javax.swing.
*
; JMenuBarmb
=
new
JMenuBar(); JMenufile
=
new
JMenu(
"
Look&Feel
"
,
true
); ButtonGroupbuttonGroup
=
new
ButtonGroup();
final
UIManager.LookAndFeelInfo[]info
=
UIManager.getInstalledLookAndFeels();![]()
for
(
int
i
=
0
;i
<
info.length;i
++
)
...
{ JRadioButtonMenuItemitem=new JRadioButtonMenuItem(info[i].getName(),i==0); finalStringclassName=info[i].getClassName();![]() item.addActionListener(newActionListener()...{![]() publicvoidactionPerformed(ActionEventae)...{![]() try...{UIManager.setLookAndFeel(className);}![]() catch(Exceptione)...{System.out.println(e);} SwingUtilities.updateComponentTreeUI(TouchyFeely.this);} }); buttonGroup.add(item); file.add(item); }
mb.add(file); setJMenuBar(mb); }
|


JRadioButtonMenuItemitem
item.addActionListener(
SwingUtilities.updateComponentTreeUI(TouchyFeely.
}

被折叠的 条评论
为什么被折叠?



