如何改善 JAVA Swing GUI 的观感?

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

How to improve look and feel of JAVA swing GUI?

javaswinglook-and-feel

提问by Mandar

I am working on a project that uses Java Swing. The default look and feel of the Java Swing GUI is very boring. Is there any way I can use a better look and feel? Something like on web pages...

我正在开发一个使用 Java Swing 的项目。Java Swing GUI 的默认外观非常乏味。有什么办法可以使用更好的外观和感觉吗?像网页上的东西...

采纳答案by Frederik Wordenskjold

You can set the look and feel to reflect the platform:

您可以设置外观以反映平台:

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

If this is not nice enough for you, take a look at SWT for Eclipse.

如果这对您来说还不够好,请查看SWT for Eclipse

回答by Michael Borgwardt

Look at the Java tutorial for setting the look and feel. In addition to those mentioned there, recent Java 6 releases also include the Nimbus Look and Feel.

查看 Java教程以设置外观。除了那里提到的那些,最近的 Java 6 版本还包括Nimbus Look and Feel

回答by extraneon

You can take a look here. I googled on java swing theme.

你可以看看这里。我在 Java Swing 主题上用谷歌搜索。

That said, if you're making a hobby project changing the LAF is no problem. If you're making software for your buddies it's also not a problem. If you make software for customers keep the swing default. It works well and isn't too exciting:)

也就是说,如果你正在做一个爱好项目,改变 LAF 是没有问题的。如果您正在为您的好友制作软件,这也不是问题。如果你为客户制作软件保持swing默认。它运作良好,并不太令人兴奋:)

回答by Carl Smotricz

Another option is the Plastic Look-and-feel. It gives Swing apps an XP-like look and offers a lot of customization options.

另一种选择是塑料外观。它为 Swing 应用程序提供了类似 XP 的外观,并提供了许多自定义选项。

EDIT: I just noticed that the images on that page are broken. If you click through to the JGoodies Looks page, you at least see 3 examples of what you can accomplish with those looks.

编辑:我刚刚注意到该页面上的图像已损坏。如果您点击进入JGoodies Looks 页面,您至少会看到 3 个示例,说明您可以使用这些外观完成什么。

回答by Russ Hayward

Substance is a very configurable and modern LAF:

Substance 是一个非常可配置且现代的 LAF:

https://github.com/kirill-grouchnikov/substance

https://github.com/kirill-grouchnikov/substance

回答by ryanpvw

if you're good with Photo shop you could declare the JFrame as undecorated and create your own image that will server as your custom GUI.

如果您擅长 Photo shop,您可以将 JFrame 声明为未装饰并创建您自己的图像,作为您的自定义 GUI。

in this example refer to the JFrame as frame.

在本例中,将 JFrame 称为框架。

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
//If you want full screen enter frame.setExtendedState(JFrame.MAXIMIZE_BOTH);
frame.setUndecorated(true);

now that the JFrame has its own border and custom GUI, if you defined your own custom buttons for minimize, maximize, and exit you need to lay a JPanel over the buttons and declare what those buttons will do in a action listener function(lol sorry...I don't know if it's called function like c++ or class...) for example we will refer to the JPanel as panel and we will set up a exit button.

现在 JFrame 有自己的边框和自定义 GUI,如果你定义了自己的自定义按钮来最小化、最大化和退出,你需要在按钮上放置一个 JPanel 并声明这些按钮将在动作侦听器函数中做什么(哈哈对不起...我不知道它是被称为像c++还是类的函数...)例如我们将JPanel称为面板,我们将设置一个退出按钮。

panel.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
System.exit(JFrame.EXIT_ON_CLOSE);
});
}