Swing desktop-development

自作多情 提交于 2019-12-12 07:37:13

问题


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.


回答1:


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

  • website
  • demo (direct webstart link)
  • Screenshot of a typical layout using the FormLayout

Validation framework

  • website
  • demo webstart
  • Screenshot of their validation framework in action




回答2:


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.




回答3:


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 ;-)



来源:https://stackoverflow.com/questions/9392463/swing-desktop-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!