Java 如何在 Swing 中做出好的 gui 设计

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

How to make good gui design in Swing

javauser-interfaceswing

提问by ibrahimyilmaz

Hi StackOverFlow Family

嗨 StackOverFlow 家族

I've develop a Java Swing application but I want to improve the design of my Swing frames. I search for this issue in google, but i cant find an adequate solution. Please share your experiences and opinions regarding this issue.

我已经开发了一个 Java Swing 应用程序,但我想改进我的 Swing 框架的设计。我在谷歌搜索这个问题,但我找不到合适的解决方案。请分享您对这个问题的经验和意见。

p.s. Maybe this question is not good for you but it is important for me and other like me

ps 也许这个问题不适合你,但对我和其他像我这样的人很重要

采纳答案by OscarRyz

Go and buy this book:

去买这本书:


(source: filthyrichclients.org)


(来源:filthyrichclients.org

From the description page:

从描述页面:

Filthy rich clients are applications that are so graphically rich that they ooze cool. They suck the user in from the outset and hang onto them with a death grip of excitement. They make the user tell their friends about the applications.

In short, they make the user actually enjoy their application experience. When was the last time you enjoyed using a software application?

Maybe you need more Filthy Rich Clients in your life.

肮脏的富客户端是图形丰富的应用程序,它们看起来很酷。他们从一开始就把用户吸进去,然后兴奋地死死抓住他们。他们让用户告诉他们的朋友有关应用程序的信息。

简而言之,它们让用户真正享受他们的应用体验。您最后一次喜欢使用软件应用程序是什么时候?

也许您的生活中需要更多肮脏的富客户。

Read it and understand it until get a UI you like.

阅读并理解它,直到获得您喜欢的 UI。

:)

:)

回答by Abboq

Joel Spolsky has a great article: User Interface Design for Programmers. It doesn't address Swing specifically, but it explains how to design simple, efficient UIs for a non-programmer audience.

Joel Spolsky 有一篇很棒的文章:程序员的用户界面设计。它没有专门针对 Swing,但它解释了如何为非程序员受众设计简单、高效的 UI。

回答by Abboq

Well, I'll give you my experience. I prefer SWT & Eclipse in general, simply because it integrates much more nicely and is so flexible with extension points and whatnot, but I appreciate sometimes that's overkill.

好吧,我给你我的经验。总的来说,我更喜欢 SWT 和 Eclipse,只是因为它集成得更好,并且在扩展点等方面非常灵活,但我很欣赏有时这有点矫枉过正。

When using swing, I nearly always use GridBagLayout unless the form is very simple. This is because most GUIs I design or experience contain lots of elements that aren't necessarily laid out in a flow or table-style - gridbaglayout offers the ability to draw the ui in a way java likes + allow resize if necessary, or you can prevent this from happening.

使用 Swing 时,除非表单非常简单,否则我几乎总是使用 GridBagLayout。这是因为我设计或体验的大多数 GUI 都包含许多不一定以流或表格样式布局的元素 - gridbaglayout 提供了以 java 喜欢的方式绘制 ui 的能力 + 必要时允许调整大小,或者您可以防止这种情况发生。

Specific things I make use of:

我使用的具体东西:

GridBagConsts.insets = new Insets(2,2,2,2);

This adds padding to any cell in the gridbaglayout, making it look more like a program designed for Gtk/by MS than something I threw together.

这为 gridbaglayout 中的任何单元格添加了填充,使其看起来更像是为 Gtk/by MS 设计的程序,而不是我拼凑的东西。

try 
{
  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) 
{
  System.out.println("Error setting native LAF: " + e);
}

Setting the look and feel to that of the system - I'm not a fan of whatever the builtin theme (metal) is and integrating with the system is much more friendly.

将外观和感觉设置为系统的外观 - 我不喜欢任何内置主题(金属),并且与系统集成要友好得多。

That's about it for hard and fast rules. Things I suggest you look at:

这就是硬性规则。我建议你看的东西:

Other than that, it is very much application-specific and you'll need to read up on general UI design. In general, it helps to use built in controls and tools i.e. those that look like the system. The Java Class Library, for example, includes File Choosers: http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.htmlwhich when set to the system LAF appear like Windows or Gnome(-ish) choosers. Taking steps to look familiar with every other application will, in turn, make your application easier to use.

除此之外,它非常特定于应用程序,您需要阅读一般的 UI 设计。通常,使用内置控件和工具(即看起来像系统的控件和工具)会有所帮助。例如,Java 类库包括文件选择器:http: //java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html,当设置为系统 LAF 时,它看起来像 Windows 或 Gnome(-ish ) 选择器。采取措施使每个其他应用程序看起来很熟悉,反过来会使您的应用程序更易于使用。

回答by monojohnny

Also take a look at JSR-296: which is an attempt to formalize some of the aspects of putting together an application, like how to handle resource-bundles , how to fire of 'tasks' (background and modal etc).

还可以看看 JSR-296:它试图将应用程序组合在一起的一些方面形式化,例如如何处理资源包、如何触发“任务”(背景和模式等)。

The current (and some previous versions) of Netbeans has a Wizard to build JSR-296 apps. ("Desktop Applications").

当前(和一些以前的版本)的 Netbeans 有一个向导来构建 JSR-296 应用程序。(“桌面应用程序”)。

http://jcp.org/en/jsr/detail?id=296

http://jcp.org/en/jsr/detail?id=296