如何改善 JAVA swing GUI 的外观和感觉?

发布于 2024-08-27 14:27:16 字数 90 浏览 4 评论 0原文

我正在开发一个使用 Java Swing 的项目。 Java Swing GUI 的默认外观非常无聊。有什么方法可以让我获得更好的外观和感觉吗?比如网页上的东西...

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑红尘 2024-09-03 14:27:16

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

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

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

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.

尝蛊 2024-09-03 14:27:16

如果您擅长使用 Photoshop,您可以将 JFrame 声明为未修饰并创建您自己的图像,该图像将用作您的自定义 GUI。

在此示例中,将 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);

现在 JFrame 有了自己的边框和自定义 GUI,如果您定义了自己的自定义按钮用于最小化、最大化和退出,您需要在按钮上放置一个 JPanel 并声明这些按钮在操作侦听器函数中将执行的操作(哈哈抱歉...我不知道它是像c++那样称为函数还是类...)
例如,我们将 JPanel 称为面板,并且我们将设置一个退出按钮。

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

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.

in this example refer to the JFrame as frame.

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.

panel.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
System.exit(JFrame.EXIT_ON_CLOSE);
});
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文