Yay*_*tcm 9 java swing jframe look-and-feel uimanager
我有点困惑在哪里把这个:
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch(Exception e){
}
Run Code Online (Sandbox Code Playgroud)
我没有扩展JFrame课程,但使用了JFrame f = new JFrame();
谢谢:D
kle*_*tra 12
注意:这不是问题的答案(在哪里设置LAF).相反,它正在回答如何以独立于其包名的方式设置LAF 的问题.在类被移动的情况下简化生活,如从com.sun*到javax.swing的fi Nimbus.
基本方法是查询UIManager以获取其安装的LAF,循环遍历它们直到找到匹配并设置它.这里有在SwingX中实现的方法:
/**
* Returns the class name of the installed LookAndFeel with a name
* containing the name snippet or null if none found.
*
* @param nameSnippet a snippet contained in the Laf's name
* @return the class name if installed, or null
*/
public static String getLookAndFeelClassName(String nameSnippet) {
LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();
for (LookAndFeelInfo info : plafs) {
if (info.getName().contains(nameSnippet)) {
return info.getClassName();
}
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
用法(此处无异常处理)
String className = getLookAndFeelClassName("Nimbus");
UIManager.setLookAndFeel(className);
Run Code Online (Sandbox Code Playgroud)
Byr*_*ach 11
放置它的最常见的地方就在你的静态void main(String [] args)方法中.像这样:
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch(Exception ignored){}
new YourClass(); //start your application
}
Run Code Online (Sandbox Code Playgroud)
欲了解更多信息,请访问该网站:http: //docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
UIManager.setLookAndFeel()将不适用于已创建的组件.这是为应用程序中的每个窗口设置外观的好方法.这将在程序中的所有打开的Windows上设置它.创建的任何新窗口都将使用UIManager设置的内容.
UIManager.setLookAndFeel(lookModel.getLookAndFeels().get(getLookAndFeel()));
for(Window window : JFrame.getWindows()) {
SwingUtilities.updateComponentTreeUI(window);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
44403 次 |
| 最近记录: |