Java GUI 框架.选择什么?Swing、SWT、AWT、SwingX、JGoodies、JavaFX、Apache Pivot? [英] Java GUI frameworks. What to choose? Swing, SWT, AWT, SwingX, JGoodies, JavaFX, Apache Pivot?

查看:91
本文介绍了Java GUI 框架.选择什么?Swing、SWT、AWT、SwingX、JGoodies、JavaFX、Apache Pivot?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 有很多 gui 框架,但目前公认的首选框架是什么?

There is quite a lot of gui frameworks out there for java, but what is recognized as today's framework of choice?

以下是我对不同框架的理解,如有不对请指正.这是一组定义非常松散的问题,但我仍然认为它对任何想要创建丰富的 gui 应用程序的人都很有价值.

The following is my understanding of the different frameworks, please correct me if im wrong. This is a very loosely defined set of questions, but i still think its valuable for anyone thinking of creating rich gui applications.

AWT

是swing的基础,性能不错,但缺少高级组件.如果您打算创建丰富的应用程序,AWT 可能不是要走的路.但是对于不需要丰富用户界面的较小的 gui 应用程序.这可能非常适合,因为它是一个久经考验的框架.

Is the very foundation of swing, it performs well but is lacking in advanced components. If you intend to create rich applications, AWT is probably not the way to go. However for smaller gui applications that doesn't require rich user interfaces. This might suit perfectly as it's a tried and proven framework.

摇摆

如前所述,基于 AWT.在它的初期,它被认为是缓慢和有缺陷的,并导致 IBM 为 Eclipse 创建了 SWT.然而,在 Java 5(或 6?)中,Swing 成为构建新应用程序的首选框架.Swing 有很多丰富的组件,但在某些方面仍然缺乏.一个例子是没有一个功能齐全的 TreeTable 组件可以进行排序和过滤/搜索.

Based on AWT as previously stated. In its infancy it was regarded as slow and buggy and caused IBM to create SWT for Eclipse. However with Java 5 (or 6?) Swing became the framework of choice for building new applications. Swing has a lot of rich components but are still lacking in some areas. One example being that there isn't a full featured TreeTable component which can do sorting and filtering/searching.

SWT

IBM 为 Eclipse 创建的,当时他们似乎认为 Swing 不适合 Eclipse.本身是相当低级的,它通过 JNI 使用平台的本机小部件.它与 Swing 和 AWT 完全无关.然而,他们的 API 有点笨拙且不直观.他们确实有一些高级组件,例如 TreeTable.(但我认为它们不支持开箱即用的排序和过滤).SWT 使用一些本机绑定(通过 JNI?),互联网上的咆哮是这个框架不应该在今天的项目中使用.(为什么不呢?)

Created by IBM for Eclipse, they seemed to think that Swing was not suited for Eclipse at the time. By itself is pretty low-level, and it uses the platform's native widgets through JNI. It is not related to Swing and AWT at all. Their API is however somewhat clunky and not intuitive. They do have some advanced component's like a TreeTable. (but i don't think they support sorting and filtering out of the box). SWT uses some native bindings (through JNI?) and the rant on the internet is that this framework should not be used in today's projects. (why not?)

SwingX

基于 Swing,其使命是为 Swing 创建丰富的组件.仍在开发中.(虽然不是很活跃.)有一组非常好的组件,例如 TreeTable.但据我所知,TreeTable 不支持过滤和排序.但是,它确实支持通过突出显示进行搜索.

Based on Swing and it's mission is to create rich components for swing. Still under development. (not very active though.) Have a very nice set of components, like for example TreeTable. But the TreeTable does not support filtering and sorting as far as i know. It does however support searching with highlighting.

请注意,SwingX 是组件 (AFAIU),它们是扩展或现有 Swing 组件的组合

Note that SwingX is components (AFAIU) that are extensions or compositions of existing Swing components

<小时>

JGoodies

一个我一无所知的框架......它的优点和缺点是什么?Jgoodies 与其他产品有何不同?

A framework which i know nothing about... What is it's strengths and weaknesses? What set's Jgoodies apart from the rest?

JGoodies OTOH 是关于 PLAF 和布局.

JGoodies OTOH is about PLAFs and layouts.

<小时>

JavaFX

Java/Oracle 的最新旗舰.有望成为开发丰富桌面或 Web 应用程序的事实标准.

The latest flagship of Java/Oracle. promising to be the facto standard in developing rich desktop or web applications.

Apache Pivot

它使用 Java2D 呈现 UI,从而最大限度地减少 Swing 和 AWT 的(IMO,臃肿)遗留的影响.(@Augustus Thoo)

It renders UI using Java2D, thus minimizing the impact of (IMO, bloated) legacies of Swing and AWT. (@Augustus Thoo)

它的主要重点似乎是 RIA(富互联网应用程序),但它似乎也可以应用于桌面应用程序.作为个人评论,看起来很有趣!我特别喜欢它是一个 apache 项目.

It's main focus seems to be on RIA (Rich internet applications), but it seems it can also be applied to desktop applications. And as a personal comment, Looks very interesting! I Especially like that it's an apache project.

https://cwiki.apache.org/PIVOT/frequently-asked-questions-faq.html

Qt Jambi

原生 qt 库的 java 包装器,用 c/c++ 编写.非常强大,被广泛使用和接受.拥有大量 GUI 组件和易于使用的 API.

A java wrapper to the native qt library which is written in c/c++. Very powerful, widely used and accepted. Has a lot of GUI components and a easy to use API.

http://qt-jambi.org/

所以,尝试总结一下我的要求:

So, to try to summarize a bit of what im asking:

假设我今天想用 Java 创建一个桌面应用程序,它涉及很多高级组件,我应该选择什么?为什么?

Say i wanted to create a desktop application today in Java which involves a lot of advanced components, what should i choose? And why?

这些框架中的哪一个应该被认为已弃用,哪些应该被认为是遥远未来的框架?

Which one of these frameworks should be recognized as deprecated and which should be recognized as the frameworks of the distant future?

当今事实上的标准框架是什么?您使用哪些工具来创建 java gui 应用程序?

What is todays de-facto-standard framework and which tools do you utilize to create java gui applications?

我可能会后悔问这个问题,但无论如何我都不会尝试:

I might regret asking this, but ill try it anyways:

C#/.Net 据说有一套非常好的易于使用的组件,可以在任何可能的方向上进行弯曲.在某种程度上调查了不同的 Java 框架之后,我似乎无法对 Java 说同样的话.为什么是这样?为什么 java(世界上使用最广泛的编程语言)没有相同的 GUI 组件集?

C#/.Net is said to have a very good set of easy to use components which can be flexed in every direction possible. And after investigating different java frameworks to some extent i can't seem to say the same about Java. Why is this? Why doesn't java (which is the most widely used programming language in the world) have the same set of GUI components?

难道只是 java 的 gui 组件基于低得多的级别,并且可以编写我正在寻找的所有这些高级组件,但您必须自己做很多工作吗?

Is it just that java has based their gui components at a much lower level, and it is possible to write all these advanced components that im looking for, but you have to do much if not all of the work yourself?

推荐答案

决策树:

  1. 像 Qt 和 SWT 这样的框架需要本机 DLL.所以你必须问自己:是否支持所有必要的平台?您可以将本机 DLL 与您的应用程序一起打包吗?

  1. Frameworks like Qt and SWT need native DLLs. So you have to ask yourself: Are all necessary platforms supported? Can you package the native DLLs with your app?

见这里,如何为 SWT 执行此操作.

如果你在这里有一个选择,你应该更喜欢 Qt 而不是 SWT.Qt 是由了解 UI 和桌面的人开发的,而 SWT 的开发是为了使 Eclipse 更快.它更像是 Java 1.4 的性能补丁而不是 UI 框架.如果没有 JFace,您将缺少许多主要的 UI 组件或 UI 组件的非常重要的功能(例如对表格进行过滤).

If you have a choice here, you should prefer Qt over SWT. Qt has been developed by people who understand UI and the desktop while SWT has been developed out of necessity to make Eclipse faster. It's more a performance patch for Java 1.4 than a UI framework. Without JFace, you're missing many major UI components or very important features of UI components (like filtering on tables).

如果 SWT 缺少您需要的功能,则该框架对扩展它有些敌意.例如,你不能在其中扩展任何类(这些类不是最终的,它们只是在 this.getClass() 的包不是 org.eclipse 时抛出异常.swt 并且您无法在该包中添加新类,因为它已签名).

If SWT is missing a feature that you need, the framework is somewhat hostile to extending it. For example, you can't extend any class in it (the classes aren't final, they just throw exceptions when the package of this.getClass() isn't org.eclipse.swt and you can't add new classes in that package because it's signed).

如果您需要原生的纯 Java 解决方案,剩下的就交给您了.让我们从 AWT、Swing、SwingX - Swing 方式开始.

If you need a native, pure Java solution, that leaves you with the rest. Let's start with AWT, Swing, SwingX - the Swing way.

AWT 已过时.Swing 已经过时了(也许不那么过时,但在过去 10 年中在 Swing 上所做的工作并不多).您可能会争辩说 Swing 一开始就很好,但我们都知道代码会腐烂.对于当今的用户界面而言尤其如此.

AWT is outdated. Swing is outdated (maybe less so but not much work has been done on Swing for the past 10 years). You could argue that Swing was good to begin with but we all know that code rots. And that's especially true for UIs today.

这让您使用 SwingX.经过较长时间的缓慢进展,开发再次回升.Swing 的主要缺点是它保留了一些旧想法,这些想法在 15 年前非常流行,但今天感觉笨拙".例如,表视图确实支持过滤和排序,但您仍然必须配置它.您必须编写大量样板代码才能获得一个感觉现代的体面 UI.

That leaves you with SwingX. After a longer period of slow progress, development has picked up again. The major drawback with Swing is that it hangs on to some old ideas which very kind of bleeding edge 15 years ago but which feel "clumsy" today. For example, the table views do support filtering and sorting but you still have to configure this. You'll have to write a lot of boiler plate code just to get a decent UI that feels modern.

另一个薄弱环节是主题化.截至今天,有很多主题.请参阅此处查看前 10 名.但有些很慢,有些是错误的,有些是不完整的.当我编写 UI 时,我讨厌它并且用户抱怨某些东西对他们不起作用,因为他们选择了一个奇怪的主题.

Another weak area is theming. As of today, there are a lot of themes around. See here for a top 10. But some are slow, some are buggy, some are incomplete. I hate it when I write a UI and users complain that something doesn't work for them because they selected an odd theme.

JGoodies 是 Swing 之上的另一个层,就像 SwingX.它试图使 Swing 使用起来更愉快.该网站看起来很棒.让我们来看看教程......嗯......还在寻找......等一下.网站上似乎根本没有文档.谷歌救援.不,根本没有有用的教程.

JGoodies is another layer on top of Swing, like SwingX. It tries to make Swing more pleasant to use. The web site looks great. Let's have a look at the tutorial ... hm ... still searching ... hang on. It seems that there is no documentation on the web site at all. Google to the rescue. Nope, no useful tutorials at all.

我对 UI 框架没有信心,因为它如此努力地向潜在的新粉丝隐藏文档.这并不意味着 JGoodies 不好;我只是找不到什么好说的,但它看起来不错.

I'm not feeling confident with a UI framework that tries so hard to hide the documentation from potential new fans. That doesn't mean JGoodies is bad; I just couldn't find anything good to say about it but that it looks nice.

JavaFX.很棒,很时尚.支持在那里,但我觉得它更像是一个闪亮的玩具,而不是一个严肃的 UI 框架.这种感觉源于缺乏复杂的 UI 组件,如树表.有一个 基于 webkit 的组件来显示 HTML.

JavaFX. Great, stylish. Support is there but I feel it's more of a shiny toy than a serious UI framework. This feeling roots in the lack of complex UI components like tree tables. There is a webkit-based component to display HTML.

当它被引入时,我的第一个想法是晚了五年".如果您的目标是一款适用于手机或网站的不错的应用程序,那很好.如果您的目标是专业的桌面应用程序,请确保它满足您的需求.

When it was introduced, my first thought was "five years too late." If your aim is a nice app for phones or web sites, good. If your aim is professional desktop application, make sure it delivers what you need.

枢轴.我第一次听说.它基本上是一个基于 Java2D 的新 UI 框架.所以我昨天试了一下.没有 Swing,只有一点点 AWT(new Font(...)).

Pivot. First time I heard about it. It's basically a new UI framework based on Java2D. So I gave it a try yesterday. No Swing, just tiny bit of AWT (new Font(...)).

我的第一印象很好.有大量文档可以帮助您入门.大多数示例都带有现场演示(注意:您必须启用 Java在您的网络浏览器中;这是一个安全风险) 在网页中,因此您可以并排看到代码和生成的应用程序.

My first impression was a nice one. There is an extensive documentation that helps you getting started. Most of the examples come with live demos (Note: You must have Java enabled in your web browser; this is a security risk) in the web page, so you can see the code and the resulting application side by side.

根据我的经验,更多的精力花在代码上而不是文档上.通过查看 Pivot 文档,一定在代码中付出了很多努力.请注意,目前有一个错误会阻止某些示例工作(PIVOT-858) 在浏览器中.

In my experience, more effort goes into code than into documentation. By looking at the Pivot docs, a lot of effort must have went into the code. Note that there is currently a bug which prevents some of the examples to work (PIVOT-858) in your browser.

我对 Pivot 的第二印象是它易于使用.当我遇到问题时,我通常可以通过查看示例来快速解决它.不过,我缺少每个组件支持的所有样式的参考.

My second impression of Pivot is that it's easy to use. When I ran into a problem, I could usually solve it quickly by looking at an example. I'm missing a reference of all the styles which each component supports, though.

与 JavaFX 一样,它缺少一些更高级别的组件,例如树表组件 (PIVOT-306).我没有尝试使用表视图进行延迟加载.我的印象是,如果底层模型使用延迟加载,那就足够了.

As with JavaFX, it's missing some higher level components like a tree table component (PIVOT-306). I didn't try lazy loading with the table view. My impression is that if the underlying model uses lazy loading, then that's enough.

有希望.如果可以,请尝试一下.

Promising. If you can, give it a try.

这篇关于Java GUI 框架.选择什么?Swing、SWT、AWT、SwingX、JGoodies、JavaFX、Apache Pivot?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆