views:

786

answers:

10

I know how to create the basic controls in Swing, but coming to industry standard application development, I lack the skills to do them.

I am designing a small Java Swing application. Instead of creating a JFrame for each purpose, I would like to create controls, display them, hide them (whenever necessary), everything in just one window.

How can I do it? I am a beginner. Please point me to nice web resources on the conventional ways of doing desktop Java applications using Swing.

+1  A: 

Read a good book on the topic, such as Core Java or Professional Java User Interfaces.

SLaks
+4  A: 

This is the most-read tutorial on Swing without a doubt. Run through the tutorial from beginning to end if you have time, to learn the Swing way of doing things.

At the same time, try to locate a copy of JBuilder to see the template code that it creates for Swing apps. You will code by hand using Eclipse or whatever, but JBuilder can show you some standard ways of doing things. If you can't get a copy, check out some of the Swing plugins for Eclipse. In all cases, try to keep in touch with the code yourself: most UI editors are only helpful in the suggestions they give you.

Yar
+5  A: 

I suggest you use NetBeans and create a project using the "Swing Desktop Application" pre-existing template.

It will create the basic infrastructure for your app including a main window with a menu and status bar with a progress bar, about box, event handlers, etc, all pre-wired.

What's nice about it for example is that the progress bar is already configured to listen to any action task that you create, so by simply creating a new action task, you get a working progress bar that will run when the task executes, without having to code it.

For more info see here.

JRL
So that will make a normal Swing app, right, not a Netbeans-based app?
Yar
@yar: it'll make a standard Swing Application Framework desktop application. By default to use the NetBeans GUI drag and drop the IDE will create resource files for you, but you don't have to use them and you can configure the IDE to not use them. But then you lose the RAD GUI development.
JRL
Very cool and interesting stuff. Should I ever head back to Java (now doing some UI in Mono Winforms), I'll be sure to check out Netbeans. I use Netbeans for all of my paid gigs right now (Ruby on Rails and PHP).
Yar
+2  A: 

Run through the tutorial suggested by yar. I'd also recommend the excellent book, "Filthy Rich Clients" by Romain Guy and Chet Haase (two big names in the Swing world). It'll teach you to make apps that look great.

GaryF
+1  A: 

I haven't worked with it much, but the Griffon project is attempting to standardize the MVC pattern for Swing applications. However, it's written in the Groovy scripting language, which then runs on the JVM.

Jason Gritman
A: 

JDock offers a docking framework, allowing you to present your application in a single frame, divided into separate dockable areas. I confess I've never tried it though.

Adamski
A: 

Spring RCP is one, although risky solution. It has some nice features and in my opinion it works pretty well for the most part. However, the documentation is close to non-existing and the future of the project is uncertain. There are some users (including me) committed to RCP though, so it will probably not die completely.

Carlos
A: 

This SO question might be helpful.

cetnar
This is not an answer, you can leave comments to the question instead.
Jonas
+3  A: 

Im not sure where i read this (old article), but since i read it i use it in all commercial desktop applications i make.

First thing get Netbeans, its the perfect IDE for Java UI design. The other Eclipse plugins are not as helpful nor powerful.

Here is how i do it.

In Netbeans, create a new Java project, lets call it MyComponents in this project, create all your components you want. The base of any component should be a JFrame or a JPanel For this example will choose JPanel and call it mjPanel alt text

Next in the Design view, drag and drop all the Swing components you want. Then from the Source view, make all the actions and logic. alt text

Next, the most important step, right click your Java file, from Tools, choose Add to Palette, then in the dialog, choose where you want to put it, like say Swing Components Palette. alt text


To finalize your component, from Build menu, choose Clean and Build, this will create you a Jar file in the project folder/dist.

From now on, in each project you want to use this component, just include the Jar file in your project classpath. Open the Swing Components Palette, and you will see your new component. Like this: alt text

Hope this helps

medopal
A: 

The Java Look and Feel Design Guide offers a detailed reference about the standards in user interface design with Swing and metal look and feel. If you are planning to use this cross platform l&f, I definitely recommend you the reading.

Massimiliano Fliri