Swing 桌面开发

发布于 2025-01-07 18:32:08 字数 1640 浏览 1 评论 0 原文

我有一个关于 java 桌面 GUI 应用程序的非常普遍的问题。

我的经验: 在过去的几年里,我开发了许多桌面应用程序,其中一些单独使用 Swing,一些使用 Spring-RCP(这很棒,但我仍然不能只押注于一个已经超过 3 年没有更新的框架) 。我也在看《Valkyrie RCP》,但在我看来,那里也确实没有那么多动静。我还使用 Wicket、Tapestry 以及最近的 JSF2 (Primefaces) 开发了 Web 应用程序。在获得了一些 Web 应用程序的经验后,我感觉 java 桌面 GUI 已经被放弃很久了。当然,我之前没有注意到这一点,但是在开发网络应用程序之后,我真的看到直接比较桌面用户界面编程是多么痛苦和复杂。

我在寻找什么: 我在这里没有做任何火箭科学,我最怀念的是一种构建以下简单布局形式的简单方法,

label_a    input_a    feedbackMessage_a
label_b    input_b    feedbackMessage_b
....
button_save

这不仅仅是布局,这可能是最小的问题。首先,我正在寻找一种将输入字段的值“绑定”到某种“支持 bean 字段”的方法。另外,我想使用直接反馈,这意味着如果 input_a 验证失败,我希望在 FeedbackMessage_a 处显示一条消息,而不是在其他地方显示消息。第三,我想使用 JSR-303 验证和直接反馈。 如果我深入研究典型桌面应用程序的源代码,我通常会看到每个按钮都有一个巨大的动作监听器,其中所有的值分配、验证和反馈消息创建都是手动编写的。将此与 Tapestry 或 jsf2 等 Web 框架进行比较。您要做的就是使用某种表达式语言将输入字段“绑定”到变量/字段,就是这样。该值正在被验证(例如使用 JSR-303 注释)并且(如果所有值都有效)自动传递到支持 bean 的绑定字段中。此外,如果发生验证错误,则会创建一条验证消息,其中输入字段的 id 用于标识负责的输入字段。如果该特定 ID 存在消息组件,则验证消息将在那里设置。一切顺利且合乎逻辑。

现在跳回桌面 GUI;要拥有一个可比较的用户界面,例如具有 20 个输入字段的表单,我可能需要 500 行侦听器代码,其中我首先自己读取每个文本字段的值,自己验证它,然后自己将其写入相应的变量中。如果我要使用 JSR-303,我可以自己调用验证器,但是回溯到相应的输入字段并在那里设置反馈消息会很痛苦......猜猜看......我自己!很痛苦,不是吗?

我的问题: 有什么办法可以缓解疼痛吗?如何开发现代桌面应用程序?您使用什么框架以及为什么?是否有可能使用类似于 webframeworks 的绑定方式?我如何实现“直接反馈”,如上所述?我是否错过了这里的火车,或者在过去几年中编写 Web 应用程序真的变得更加简单,而 java-desktop 似乎陷入了困境? (除了JavaFx,但这对我没有一点帮助)

最后的话 不要误会我的意思,我是 Java 桌面应用程序的忠实粉丝。在像我工作的这样一家中等规模的公司中,具有同质环境(所有客户端都安装了相同的 java 版本等),我真的看不到 Web 应用程序的好处。使用 webstart,应用程序启动速度非常快(当然是在第一次启动下载之后)。 在我看来,虽然 Java 中以前端为中心的 Web 框架以光速向前发展,但 java-desktop 几乎没有任何进展。 虽然我可以接受现状,但我真的不得不问这个问题。

I have a very general question regarding java desktop-gui-applications.

My Experience:
In the last years i have developed a number of desktop-applications, some using Swing alone, some Spring-RCP (which was great, still i can't just bet on a framework that has not seen an update for over 3 years anymore). I am also watching Valkyrie RCP, but it seems to me that there is really not that much movement there either. I also developed web applications with Wicket, Tapestry and more recently with JSF2 (Primefaces). Having gained some experience in web-applications it feels to me like java desktop-gui has been abandoned a long time ago. Of course i didn't notice that before, but after developing web-apps, i really see how painful and complicated programming desktop-uis is in direct comparison.

What i am looking for:
I am not doing any rocket science here, what i miss the most is an easy way to build a form of the following simple layout

label_a    input_a    feedbackMessage_a
label_b    input_b    feedbackMessage_b
....
button_save

It's not only about the layout, that is probably the smallest problem. First i am looking for a way to "bind" values of input-fields to some sort of "backing-bean-fields". Also i want to use direct feedback, meaning that if validation of input_a fails, i want a message displayed at feedbackMessage_a and nowhere else. Third i want to use JSR-303 validation with this direct feedback.
If i dig into the sourcecode of a typical desktop-application, i usually see a giant action-listener for every button, where all that value-assignment, validation and feedback-message-creation was written manually. Compare this to a webframework like tapestry or jsf2. What you would do there, is to "bind" an inputfield to a variable/field with some sort of expression-language, and that is it. The value is getting validated (e.g. using JSR-303 Annotations) and (if all values where valid) passed into the binded field of the backing bean automatically. Also if an validation error occures, a validation message is created, where the id of the inputfield is used to identify the input-field that is responsable. If a message-component exists for that specific id, the validation message is set there. It's just smooth and logical.

Now jumping back to desktop-gui; to have a comparable user-interface for lets say a form with 20 inputfields, i would probably need like 500 lines of listener-code, where i first read the value of every textfield myself, validate it myself and write it in the corresponding variable myself. If i were to use JSR-303 i could call the validator myself, but it would be painful to backtrack to the corresponding inputfield and set the feedback-message there..guess what.. myself! Painful, isn't it?

My Questions:
Is there any way to easy the pain? How do you develop modern desktop-applications? What frameworks do you use and why? Is there any possibility to use a similar way of binding like webframeworks do? How can i implement "direct feedback", like explained above? Did i miss a train here or has it really become that much simpler to write a web application in the last few years, while java-desktop seems to be stuck? (Except for JavaFx, but that doesn't help me a bit)

Final words
Don't get me wrong, i am big fan of java desktop-applications. In a moderate-sized company like the one i am working in, with a homogeneous environment (where all clients have the same java-version installed and so on) i really don't see the gain of a webapplication. Using webstart, the application starts really fast (after the first start with download of course).
Still it appears to me that while frontend-centric webframeworks in Java move forward with light-speed, java-desktop is nearly not moving at all.
Although I can live with the way it is i really have to ask this questions.

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

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

发布评论

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

评论(3

掌心的温暖 2025-01-14 18:32:08

我从使用 JGoodies 验证框架的用户那里听到了很好的反馈,甚至与他们的 FormLayout 结合使用,顾名思义,它是一个 LayoutManager 专门设计用于使组件看起来就像表格一样。

我个人只有 FormLayout 和内部开发的绑定框架的经验,其中您所描述的 UI 的创建归结为每个标签编辑器组合的一行。
当然有一些可用的库可以为您提供这些,但我没有使用它们的经验,因此没有这方面的建议。

FormLayout

验证框架

I heard good feedback from users who used the validation framework from JGoodies, even in combination with their FormLayout which, as the name suggests, is a LayoutManager specifically designed to make components look like forms.

I personally have only experience with the FormLayout and an in-house developed binding framework, where the creating of a UI as you describe boils down to a one-liner for each label-editor combination.
There are certainly libraries available out-there which give you just that, but I have no experience with them so no recommandations on that front.

FormLayout

Validation framework

木槿暧夏七纪年 2025-01-14 18:32:08

我可以建议看一下 Eclipse Scout 吗?它基于 Java/Eclipse,并可在 EPL 下使用。

Scout 主要致力于构建业务应用程序。通过将客户端 ui 模型与实际 ui 渲染完全分离,您可以选择使用 Eclipse SWT、Swing 或 Web 应用程序(基于 Eclipse RAP,这将随 Juno 版本一起提供)运行您的应用程序。

关于您对字段验证的问题,我相信您会发现所提供的机制(覆盖所需字段的 execValidate() 方法)使用起来很舒服。

请查看我们的 wiki 页面上的可用教程。如果您需要仅客户端解决方案(无支持服务器),也请考虑此操作方法

有关 Eclipse Scout 的问题,请使用项目论坛。

希望这有帮助。

May I suggest to have a look at Eclipse Scout? It is Java/Eclipse based and available under the EPL.

Scout primarily addresses building business applications. With its clean separation of the client ui model from the actual ui rendering you have the options to run your app with Eclipse SWT, Swing, or web application (based on Eclipse RAP, this will come with the Juno release).

Regarding your question to field validation i am confident that you will find the provided mechanism (overwrite method execValidate() of the desired fields) comfortable to use.

Please have a look at the available tutorials on our wiki page. In case you need a client only solution (no backed server) also consider this howto.

For questions related to Eclipse Scout please use the project forum.

Hope this helps.

昵称有卵用 2025-01-14 18:32:08

您可以通过遵循流行且成功的桌面模式并结合简洁的实施风格来减轻您的痛苦。我强烈建议您学习模型-视图-演示者 (MVP) 模式和演示模型。

福勒的“组织表示逻辑”是一个很好的介绍。有关实现样式,请参阅 http://www.jgoodies 中的“Guter Schreibstil für Swing” .com/downloads/articles-and-presentations/ 幻灯片是德语,代码是英语;-)

You can reduce your pain by following popular and successful desktop patterns combined with a clean implementation style. I strongly recommend that you learn the Model-View-Presenter (MVP) pattern and Presentation Model.

A good introduction is Fowler's "Organizing Presentation Logic". For the implementation style, see "Guter Schreibstil für Swing" at http://www.jgoodies.com/downloads/articles-and-presentations/ The slides are in German, the code is English ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文