Swing桌面开发 [英] Swing desktop-development

查看:141
本文介绍了Swing桌面开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于Java Desktop-gui-applications,我有一个非常笼统的问题.

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

我的经验: 在过去的几年中,我开发了许多桌面应用程序,其中一些单独使用Swing,一些使用Spring-RCP(这很棒,但是我不能只押注一个已经超过3年没有更新的框架). .我也在看Valkyrie RCP,但是在我看来,那里也确实没有那么多动作.我还使用Wicket,Tapestry开发了Web应用程序,最近又使用JSF2(Primefaces)开发了Web应用程序.在Web应用程序方面积累了一些经验之后,我觉得Java桌面GUI已被放弃很久了.当然,我以前没有注意到这一点,但是在开发了Web应用程序之后,我真的看到直接比较台式机UI的痛苦和复杂程度.

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

这不仅与布局有关,而且可能是最小的问题.首先,我正在寻找一种将输入字段的值绑定"到某种"backing-bean-fields"的方法.我也想使用直接反馈,这意味着如果对input_a的验证失败,我希望在messageMes​​sage_a上显示一条消息,而在其他任何地方.第三,我想在此直接反馈中使用JSR-303验证. 如果我深入研究典型桌面应用程序的源代码,通常会为每个按钮看到一个巨大的动作监听器,其中所有值分配,验证和反馈消息创建都是手动编写的.将此与诸如挂毯或jsf2之类的网络框架进行比较.您将在此处执行的操作是使用某种表达式语言将输入字段绑定"到变量/字段,就是这样.该值会得到验证(例如,使用JSR-303注释),并且(如果所有值均有效)会自动传递到备用Bean的绑定字段中.同样,如果发生验证错误,则会创建一条验证消息,其中输入字段的ID用于标识负责的输入字段.如果存在用于该特定ID的消息组件,则在此处设置验证消息.这只是顺理成章.

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.

现在跳回到桌面GUI;为了有一个可比的用户界面,比如说一个带有20个输入字段的表单,我可能需要500行侦听器代码,在此我首先自己读取每个文本字段的值,然后对其进行验证并自己将其写入相应的变量中.如果我要使用JSR-303,我可以自己打电话给验证器,但是回溯到相应的输入字段并在那里设置反馈消息会很麻烦.痛苦的,不是吗?

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?

我的问题: 有什么方法可以减轻痛苦吗?您如何开发现代桌面应用程序?您使用什么框架,为什么?是否有可能像webframeworks一样使用类似的绑定方式?如上所述,我如何实现直接反馈"?我是否错过了这里的火车,还是在过去几年中编写Web应用程序变得更加简单,而java-desktop似乎仍然停滞不前? (除了JavaFx,但这对我没有帮助)

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)

最后一句话 别误会,我是Java桌面应用程序的忠实拥护者.在一个我正在工作的中等规模的公司中,在同类环境中(所有客户端都安装了相同的Java版本,依此类推),我真的看不到Web应用程序的收益.使用webstart,该应用程序启动速度非常快(当然,在首次下载后). 在我看来,尽管Java中以前端为中心的webframeworks以光速向前发展,但java-desktop几乎没有动静. 尽管我可以忍受这样的方式,但我确实必须问这个问题.

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.

推荐答案

我从使用JGoodies验证框架的用户那里得到了很好的反馈,甚至与他们的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.

我个人只有使用FormLayout和内部开发的绑定框架的经验,在该框架中,您描述的UI的创建归结为每个标签编辑器组合的一线式. 当然有可用的库可以为您提供这些信息,但是我对它们没有经验,因此在这方面没有任何建议.

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.

  • website
  • demo (direct webstart link)
  • Screenshot of a typical layout using the FormLayout
  • website
  • demo webstart
  • Screenshot of their validation framework in action

这篇关于Swing桌面开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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