UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
得到系统的。
得到系统的。
解决方案 »
- GetDate.getPreviusMonth( gc )问题!!!
- 关于JAVA引用数据类型的问题
- Java中如何对有滚动条的窗口截图
- 读写xml文件,为什么node.getNodeValue()的值为空??
- Java初学者CSDN第2问!
- 急急求,怎样可以让JTextField上怎样实现TextListener()里的textValueChanged(TextEvent e)方法;
- 在java中实现宏替换功能.
- 我看看这个题目,很简单(一起学习java 散分)
- 想认识一些开发JAVA方面程序的朋友。[email protected](MSN)
- 来写个冒泡排序
- 在动态添加DefaultListModel情况下如何让JList的最后一行总是显示出来。
- 如何将在数据库中查询的东西在网页上显示出来?
可以设置三种标准的外观之一:Windows,Motif(Unitx),或Metal(标准的Swing外观)。
设置可插入的外观
要在程序运行时改变外观,可以使用UIManager类的setLookAndFeel方法,将以下作为参数传入:
javax.swing.plaf.metal.MetalLookAndFeel; Metal外观
com.sun.java.swing.plaf.motif.MotifLookAndFeel; Motif外观
com.sun.java.swing.plaf.windows.WindowsLookAndFeel; windows外观
在改变内容板的外观后,使用SwingUtilities类的updateComponentTreeUI()方法实它起作用,
SwingUtilities.updateComponentTreeUI(getContentPane());我给你一个例子:
如果想改变默认感观,找到jdk/jre/lib/swing.properties文件
有三行#swing.defaultf语句
通过增删前面的#来改变
// Get the system Look & Feel name for current platform.
final String platform = UIManager.getSystemLookAndFeelClassName();
// If the current Look & Feel does not match the platform Look & Feel,
// change it so it does.
if (!UIManager.getLookAndFeel().getName().equals(platform))
{
try
{
UIManager.setLookAndFeel(platform);
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
// Action listener for menu items affecting the Look & Feel.
final ActionListener lookFeelActionListener = new ActionListener()
{
// When a new Swing Look & Feel is selected, apply it.
public void actionPerformed(ActionEvent event)
{
setLookAndFeel(event.getActionCommand(), fMyFrame);
}
};
// Enumerate the currently installed Look & Feels.
final UIManager.LookAndFeelInfo[] installed = UIManager.getInstalledLookAndFeels();
// For each installed Look & Feel, create a menu item using the
// Look & Feel name. Select the menu item for the platform Look & Feel
for (int i = 0; i < installed.length; i++)
{
final String name = installedi.getName();
final JMenuItem menuItem = new JRadioButtonMenuItem(name);
menuItem.addActionListener(lookAndFeelActionListener);
if (name.equals(platform))
menuItem.setSelected(true);
}
该代码获取当前平台的 Look & Feel 名称,并将它设置成当前的 Look & Feel。它定义了一个操作侦听器来处理 Look & Feel 菜单项选择。然后,它枚举了已安装的 Look & Feel,并使用 Look & Feel 名称作为构造参数,为每一个都创建一个单选按钮菜单项。代码将操作侦听器与每个菜单项都关联起来,并选择与平台 Look & Feel 匹配的菜单项。 操作侦听器调用 setLookAndFeel() 方法,将与所选菜单项和引用关联的 Look & Feel 名称传递给应用程序框架。下面显示了这个方法:
// Set the current Look & Feel according to the supplied string,
// and refresh the user interface for the supplied
private void setLookAndFeel(final String lookAndFeel, final Component component)
{
// Enumerate the currently installed Look & Feels.
final UIManager.LookAndFeelInfo[] installed = UIManager.getInstalledLookAndFeels();
// Locate and set the new Look & Feel based on the supplied name.
boolean set = false;
for (int i = 0; !set && (i < installed.length); i++)
{
final String name = installedi.getName();
if (name.equals(lookAndFeel))
{
set = true;
try
{
// refresh the UI for the component, and all of its children
UIManager.setLookAndFeel(installedi.getClassName());
SwingUtilities.updateComponentTreeUI(component);
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
}
}
此代码枚举当前安装的 Look & Feel (或者是高速缓存的),并不断迭代,直到它找到名称与所提供名称匹配的 Look & Feel。如果找到一个匹配,则代码将它设置成当前 Look & Feel。将刷新所提供的组件,包括其子节点。