我厌倦了 JButton,如何在 Java 中制作更好的 GUI?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2616448/
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-29 22:02:16  来源:igfitidea点击:

I'm tired of JButtons, how can I make a nicer GUI in java?

javauser-interfaceswing

提问by Jules Olléon

So far I've only built "small" graphical applications, using swing and JComponents as I learned at school. Yet I can't bear ugly JButtons anymore. I've tried to play with the different JButton methods, like changing colors, putting icons etc. but I'm still not satisfied. How do you make a nicer GUI in java ?

到目前为止,我只使用我在学校学到的 Swing 和 JComponents 构建了“小型”图形应用程序。然而我再也无法忍受丑陋的 JButtons 了。我尝试使用不同的 JButton 方法,例如更改颜色、放置图标等,但我仍然不满意。你如何在 java 中制作一个更好的 GUI?

I'm looking for not-too-heavy alternatives (like, without big frameworks or too complicated libraries).

我正在寻找不太重的替代方案(例如,没有大框架或太复杂的库)。

采纳答案by Bozho

Swing supports changing the Look & feel.

Swing 支持更改外观。

This tutorialexplains how:

本教程解释了如何:

UIManager.setLookAndFeel(lookAndFeelClassName);

Another way is to start your app with the L&F:

另一种方法是使用 L&F 启动您的应用程序:

java -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel MyApp

Hereis a list of 10 very nice look and feels.

这里列出了 10 个非常漂亮的外观和感觉。

回答by Roman

I am using SWT. Try it , it is really very nice java gui framework, eclipse is build around it. You can use also this plugin for eclipse to create your forms Instantiations.

我正在使用SWT。试试吧,它真的是非常好的 java gui 框架,eclipse 就是围绕它构建的。您也可以使用此插件为 Eclipse 创建您的表单实例化

回答by Hyman

Have you at least tried with nimbus look'n'feel? that is a little bit better than the others..

你至少尝试过 nimbus look'n'feel 吗?这比其他的好一点..

UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

only downside is that it requires at least Java6 update 10.

唯一的缺点是它至少需要 Java6 update 10。

回答by Martijn Courteaux

try
{
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e)
{}

回答by Bozhidar Batsov

Our project manager doesn't like JButtons as well and we're using JIDE OSSbuttons instead(and lot's of other JIDE components). SwingXalso offers an alternative - JXButton. IMO these are the two most valuable external Swing libraries around.

我们的项目经理也不喜欢 JButton,我们使用JIDE OSS按钮代替(以及许多其他 JIDE 组件)。SwingX还提供了一个替代方案——JXButton。IMO 这些是最有价值的两个外部 Swing 库。

回答by Thorbj?rn Ravn Andersen

The easiest is to stay with Swing and use a different look and feel.

最简单的方法是继续使用 Swing 并使用不同的外观和感觉。

What CAN be done easily is shown at http://www.jgoodies.com/freeware/metamorphosis/index.html(Use this this web start linkto see it in action)

http://www.jgoodies.com/freeware/metamorphosis/index.html显示了可以轻松完成的工作(使用此网络启动链接查看实际操作)

Either bundle a L&F with your program, or choose one of the built in. I like Nimbus but it must be explicitly selected in your code.

要么将 L&F 与您的程序捆绑在一起,要么选择一个内置的。我喜欢 Nimbus,但必须在您的代码中明确选择它。

回答by Chuk Lee

You may want to try JavaFX. For all its problems, I find that if you want to put a decent (preetier than Swing) interface over your Java application, its quite easy to do. Plus good Java integration. You can implement Java interfaces in JavaFX and vice versa.

您可能想尝试JavaFX。尽管存在所有问题,但我发现如果您想在 Java 应用程序上放置一个像样的(比 Swing 更漂亮的)界面,这很容易做到。加上良好的 Java 集成。您可以在 JavaFX 中实现 Java 接口,反之亦然。

回答by stacker

This articleshows how to extend JButton and overide the methods for painting the component.

文章显示了如何扩展JButton,并在此改变方法画的组件。

回答by Tedil

If you are a little bit into graphics design, you might want to consider creating your own design with Synth, which is part of the standard JRE. If you don't want to create your own, google for free existing themes which you may use.

如果您对图形设计有一点了解,您可能需要考虑使用Synth创建您自己的设计,它是标准 JRE 的一部分。如果您不想创建自己的主题,请在 google 上搜索您可以使用的免费现有主题。

Alternatives to Synth are either Synthetica(free for personal, non commercial use) or Substance("free" as in "BSD License").

Synth 的替代品是Synthetica(免费用于个人、非商业用途)或Substance(“免费”如“BSD 许可证”)。

回答by djhworld

It would be nice if Java had a similar tool to Interface Builder (the GUI development tool that comes with Xcode) - by far the best UI builder I've ever seen.

如果 Java 有一个类似于 Interface Builder(Xcode 附带的 GUI 开发工具)的工具就好了——迄今为止我见过的最好的 UI 构建器。