tags:

views:

1572

answers:

13

I am a veteran C/C++ programmer who has used Win32, MFC and WTL to write Windows apps for many years. I have some very basic Java experience, but haven't done anything with a UI. I want to start learning how to write desktop apps in Java and from what I can gather, Swing is the way to go.

My question is: where do I start? Can anyone recommend any decent books? (I do like a good programming book). I've played with Netbeans a little in the past (and was impressed with what I saw) so I'd like to use that as my Java IDE of choice if that makes any difference.

+5  A: 

Netbeans is a decent environment.

Check out the O'Reilly Java Swing (Marmoset on cover) for a pretty good look at the ins and outs. However, My edition is 2001, and I don't know if the more current ones are any good or not.

The big gotcha in Swing is: Don't do any significant work in the listeners.

chris
And don't access swing components from any thread other than the EDT (SwingUtilities.invoke* and SwingWorker are your friends)
jsight
+1 jsight. Even seemingly "safe" calls such as "setVisible()" on a top-level frame are not necessarily safe from outside the EDT.
James Schek
+15  A: 

The Swing Tutorial is very nice. That's how I taught myself swing.

Steve K
+2  A: 

That's exactly how I came to Java/Swing, from C++/MFC etc.

I have to agree that Swing is the only way to go, there's a lot to learn in terms of concepts, but if you know MFC inside out it will help (because the fundamentals aren't that different they're both event driven windowing systems, except one of them is a bag of spanners held together with string)...

I started with a copy of an IDE (Jbuilder in my case) and worked through the Sun Java Swing Tutorials

Also this beginner's guide is pretty useful for the big picture.

Richard Harrison
+1  A: 

I also like the O'Reilly Java Swing book; it's been useful to me.

Good descriptions of concepts, good references, clear, concise, and to the point. That would be my recommendation.

It's the first book I get when searching amazon for "java swing".

Also, amusingly, that search will get you a porch swing made from wood from the island of Java...

McWafflestix
+12  A: 

Once you have mastered the basics the de-facto standard book for top notch swing GUIs is Filthy Rich Clients.

johnstok
A: 

I'm sorry, but what I'd recommend is to stay clear of Swing altogether X-)
From my point of view it's veeery verbose (even for Java), but more than anything it has a confusing and unintuitive API (repaint()/refresh() comes to mind) that will haunt you with subtle bugs every day. I'd try SWT instead.. Clearer, better looking and has better performance too.

Joril
What are your credentials? How big applications have you build in Swing and SWT? Are you talking about the core APIs or about certain RCP layers on top of them?
ddimitrov
Hi :) I've been a Java dev for 3yrs, my team was to build a rich client designed to manage small-to-mid retail stores, at every level. Eventually we dropped it and went for a web UI instead (management decision).I knew my answer would be downvoted, I just had to share the pain Swing did to us :D
Joril
+3  A: 

This question and this question is very similar to yours. There are a ton of good answers here too.

jjnguy
+1  A: 

I wrote a site as part of a project whilst at University that taught students how to learn Swing through example and exercises (with a bunch of screenshots). Although I don't have personal access to it any longer, Heriot Watt University still host it. You can find the link here..

The Guidebook - Lessons in Swing

Might get you started at least :)

Spedge
A: 

Just another book recommendation: Java Swing by Matthew Robinson und Pavel Vorobiev

It's the only book i read on Swing so far so i can't compare it to the other ones. On the other hand it's the only book i needed so far, so it can't be bad.

TheMarko
+1  A: 

If your intention is to use NetBeans and its powerful GUI building capabilities I'd recommend trying to do a lot of hand coding to start with. When I conduct interview we get a lot of people who might be able to use a GUI builder, but that is not quite the same thing as 'knowing' Swing.

willcodejavaforfood
A: 

Once you get your feet wet, I highly recommend the book "Swing Hacks" to harness the full power of swing.

dotjoe
A: 

You can start to learn it by doing simple apps using Netbeans GUI editor, which gives you a quick view on your app.

Meanwhile, Swing is very flexible and powerful. Since you can do almost anything in Swing, this advantage leads to somehow deeper learning curve. To learn more, you need some good book (like java swing, or sun's swing tutorial on their web), and good understanding of MVC design pattern, Java bean style event handling, customerized rendered, etc.

Anyway, Swing is of much better OOP and MVC than the old age mixed MFC library. You should be able to learn a bit on how to design a clean a extensible app through the learning of Swing.

A: 

You should definitely see the SwingSet2 demo which comes with jdk. You can see the sources there and it is a great reference as an "how-to" about Swing objects. If I start to use a new Swing object in my application, I just check those sources to see my options.

Mustafa Zengin