更改 Java 中的默认按钮以使其看起来“更好”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10305170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:28:30  来源:igfitidea点击:

Change Default Buttons in Java to Make Them Look "Better"

javaswingjbuttoncalculatorlook-and-feel

提问by ComputerLocus

I'm essentially trying to mimic the default windows xp simple calculator. When I change the background colours of the buttons in Java it makes them look very flat and "boring". I want to make the buttons look as close as possible to the buttons in the Windows XP calculator.

我基本上是在尝试模仿默认的 windows xp 简单计算器。当我在 Java 中更改按钮的背景颜色时,它会使它们看起来非常单调和“无聊”。我想让按钮看起来尽可能接近 Windows XP 计算器中的按钮。

Here is an image comparing mine to WinXp's: calc example

这是一张将我的图像与 WinXp 的图像进行比较的图像: 计算示例

Is there some kind of method I can use to change the style of the buttons much like you can do in Visual Basic to make the buttons almost pop more or look 3D like the Windows Xp Calculator.

是否有某种方法可以用来更改按钮的样式,就像您在 Visual Basic 中所做的那样,使按钮几乎弹出更多或看起来像 Windows Xp 计算器一样 3D。

The default buttons in Java are sort of what I'm looking for except there not white there more of a blue kind of colour in a gradient.

Java 中的默认按钮是我正在寻找的,除了在渐变中没有白色还有更多的蓝色。

Is this possible, or am I stuck with ugly button?

这是可能的,还是我被难看的按钮卡住了?

回答by Jakub Zaverka

Try setting the system look and feel at the beginning of the main method:

尝试在 main 方法的开头设置系统外观:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

This will load all Swing widgets with a native-ish look.

这将加载所有具有原生外观的 Swing 小部件。

If you are insterested in what you are actually doing with this command, Oracle has a nice tutorial regarding look and feels: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

如果您对使用此命令实际执行的操作感兴趣,Oracle 有一个关于外观的不错的教程:http: //docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html