Swing desktop-development
Asked Answered
H

3

5

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.

Humorous answered 22/2, 2012 at 9:48 Comment(4)
I totally agree with your final words, I see today (and work on) web applications that only run in an intranet, there's really no real benefit of sacrificing a client's power into the browser's window boundaries. I use .NET for client/server applications, you have a nice field validation paradigm there, I don't know if Java has a similar thing though.Nafis
what about this? java2s.com/Code/Java/Swing-Components/InputVerifierExample.htmNafis
Thanks for the link. Now that i see this code i realize that Spring-RCP (which i used a lot) seems to be built up on JGoodies-Form. I will give it a shotHumorous
java desktop-gui hasn't been abandoned, it just moved into Eclipse RCP as pure-java/Swing-based technologies seemed to give up. there are many ways of implementing an Eclipse RCP app, some involve 500 lines of listener code :) some other ways are just a matter of creating a model for GUI and asking the toolchain to generate code for you.Tristis
R
5

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

Reshape answered 22/2, 2012 at 23:56 Comment(1)
Thanks for the tip. I implemented a proof of concept for me, using JGoodies-form and -binding, which works very well. However, i didn't find JGoodies-validation too helpful for my case. I don't need instant validation anyway, so i am just calling HibernateValidators validate() myself on my save-action. Every input component has a second JLabel for validation. I am using a HashMap<String,JLabel> to backtrack from a property name (which i get from HibernateValidator for every validation-error) to the corresponding JLabel. ThanksHumorous
H
4

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.

Heather answered 22/2, 2012 at 22:38 Comment(0)
B
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 ;-)

Bjorn answered 1/6, 2012 at 8:28 Comment(1)
Welcome to Stack Overflow! Thanks for posting your answer! Please be sure to read the FAQ on Self-Promotion carefully. Also note that it is required that you post a disclaimer every time you link to your own site/product.Grassplot

© 2022 - 2024 — McMap. All rights reserved.