如何在Java GUI编程中获得windows native?

Ani*_*ram 38 java windows user-interface swing

我是Java编程的新手,想知道是否有可能在Java GUI应用程序中获得Windows本机外观.显然Swing不起作用.

ten*_*ica 68

使用以下内容:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Run Code Online (Sandbox Code Playgroud)

阅读UIManager以及如何设置外观以获取更多信息.

  • @Csanesz如果你在应用程序启动后更改了L&F,当UI已经可见时,则需要`updateComponentTreeUI`,否则不需要.上述教程讨论了各种选项. (2认同)

Kum*_*tra 13

试试这个....

语法是:

UIManager.setLookAndFeel(PLAF); (Pluggable Look and Feel)

因此,您必须包含以下3行.

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

SwingUtilities.updateComponentTreeUI(frame);

updateComponentTreeUI(frame);
Run Code Online (Sandbox Code Playgroud)

SwingUtilities.updateComponentTreeUI(frame)用于在更改后刷新帧.

  • 如果在实现任何GUI组件之前运行它,则只需要第一行. (6认同)
  • a)不建议对类名进行硬编码b)不需要三行中的第三行(已在第二行中处理:-) (2认同)