Java JButton窗口外观和感觉
我想要一个JButton的外观: 我已尝试通过以下方式更改Windows的外观:Java JButton窗口外观和感觉,java,swing,jbutton,look-and-feel,Java,Swing,Jbutton,Look And Feel,我想要一个JButton的外观: 我已尝试通过以下方式更改Windows的外观: UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); 但具体表现为: 提前谢谢 将评论列转换为独立答案: // sets the look and feel to be that of the operating system's try { UIManager.set
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
但具体表现为:
提前谢谢 将评论列转换为独立答案:
// sets the look and feel to be that of the operating system's
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException |
InstantiationException |
IllegalAccessException |
UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
我投了kiheru的票,但你似乎没有在正确的时间设置它您需要在显示组件之前运行此代码-我通常会将此代码插入启动应用程序的原始run()方法中,但如果包含splashscreen,则会有所不同
另外,在将来(特别是在谈论GUI代码时,它可能会变得可怕),人们更喜欢发布可运行代码示例,这样我们就可以确切地看到您可能出错的地方:)这只是一个愚蠢的问题。。。您正在windows上运行该程序吗?(另外,如果您试图在运行时更改它,则需要调用
SwingUtilities.updateComponentTreeUI()
)。是的,我在Windows上。这是main function.OK中的第一行。那就没什么好主意了。(虽然我会使用UIManager.getSystemLookAndFeelClassName()
而不是硬编码的名称来实现可移植性)或者更确切地说,@kiheru击败我的是-+1。结果看起来像是Windows经典而不是Windows L&F:com.sun.java.swing.plaf.Windows.WindowsClassicLookAndFeel
。同意getSystemLookAndFeelClassName()
“您需要在显示组件之前运行此代码”,或者更新组件树,如中所示。这是一个很好的注释;我不确定人们什么时候会想使用这个(也许是兼容模式设计),但这是一个新的书签!