views:

138

answers:

7

Well I know basic Java and wanted to learn Swing so of course looked at the Sun website first, where this tutorial is. I was going to start it but realised it relied heavily on NetBeans, which I'm not sure about.

I'm not sure because it's learning that I want to acheive, not a nice looking program.

So I thought using NetBeans like this would be great once I know it, but I don't want to be building things without a clue what's going on underneath, and of course this could also cause problems later.

My first question is is this the right way to do it, should I try not to rely on an IDE heavily? Looking through questions on the site most people recommend using the Sun tutorial, and I've only seen one answer that agrees with what I'm thinking, and they linked to this resource which looks promising. Or perhaps I'm getting the wrong idea of the Sun tutorial, perhaps it doesn't rely on the IDE, it just seemed like that.

My second question is, if you agree with me, what resources (apart from the one above) would you recommend?

Thanks for your answers.

A: 

Actually those tutorials do reference Netbeans multiple times but usually still tell you how to do stuff in code. Once you got a fairly good grasp of how Swing in general works you will likely read each of those when you need it.

For example Using Swing Components has (more or less) in-depth notes on each of the standard UI components and Laying Out Componnents has details about the standard layout managers.

Those are – at least for me – the things I return to the most. And exclusing a very brief touch with Netbeans I never touched its GUI builder again.

Joey
A: 

I think that you should learn the language first. Using an IDE makes you more efficient, however I think can lead to problems down the road should you need to use a different IDE. I find this book highly useful, Introduction to Java Programming. All the examples in the book are in code.

npinti
That book looks like it's just for Java but it's specifically Swing I'm learning, I already have a reasonable grasp of Java
Paul
It has topics dedicated on Swing as well. As well as how to do applications that have a relatively basic GUI. You can use it as an introduction to Swing.
npinti
+1  A: 

The tutorial predominantly is about code. It's really just the one chapter on NetBeans. The rest of it is about Swing and can be done in any IDE.

I would not recommend working with a GUI builder, simply because as you say, you don't get to understand what's going on underneath. Start with simply windows and progressively work you way through adding GUI components and interacting with them. Understand the advantages of the MVC way of doing things.

And the best recommendation I can give is don't sit down to "Learn" Swing. Pick yourself out a project that interests you and you can do using Swing. By having a goal of a working program in mind, you will better absort the lessons that the tutorials give.

Derek Clarkson
IMHO that's one of the greatest downsides of Swing. It was conceived as so complex that no GUI builder can effectively cope with it and still allow the developer to do what they want. And after many hours of writing UI with Swing I still don't know how to structure my code that it's still readable and maintainable.
Joey
Yeah that's my idea. I'm thinking of making a very simple game (or perhaps something simpler first) and I thought Swing would work for that.
Paul
+1  A: 

It seems you are a beginner in swings. I would recommend not to rely on Netbeans to develop swing UI. Try to design the UI by writing code only. This will improve your knowledge base on swings and then you can go using the GUI builder available if you so wish.

RaviG
+2  A: 

I wouldn't say that Sun relies on NetBeans in their tutorials as much as references NetBeans because NetBeans is Sun's IDE.

I use Eclipse for my Java development. A good IDE can help you with the busy work, so you can focus on the problem at hand.

If you want to learn Swing, I recommend The Definitive Guide to Java Swing, Third Edition. This book takes you step by step through layouts and widgets, using and reinforcing the MVC pattern of GUI development.

For the advanced Swing developers, I recommend Swing Hacks: Tips and Tools for Killer GUIs. This book shows you some tricks to make your GUI pop.

Gilbert Le Blanc
I may well get that book, I much prefer having a hard copy of something rather than an online reference, for some reason.
Paul
I'm the same way. Even with dual monitors, I prefer a book over most online tutorials.
Gilbert Le Blanc
I learned Swing from the Core Java books in 2000 or so. Hopefully they are still as good! http://www.amazon.com/Core-Java-TM-I-Fundamentals-8th/dp/0132354764/ref=pd_sim_b_1
Tim Perry
This is getting off topic, but I found Java(TM) Programming Language, The (4th Edition) http://www.amazon.com/Java-TM-Programming-Language-4th/dp/0321349806/ref=pd_sim_b_4 to be the best book for getting someone started in Java.
Gilbert Le Blanc
I think learning anything nontrivial requires a real world project, so even though a nice looking GUI (I suppose that's what you meant by "program") isn't your goal, you can't learn the real thing without trying to make a nice looking GUI. Also I'd recommend hand coding, since GUI builders may hide too many important things, so when the abstraction leaks you won't know where to plug.
Geoffrey Zheng
A: 

I've never found GUI builders to be very useful in Java anyway. NetBeans has a very good one, but I highly recommend you build your own GUIs.

On the other hand, you may find Swing GUis somewhat verbose. There are alternatives, Java-FX apparently has a declarative language that you can define your GUI in while writing everything else in Java.

Also Groovy has a nice declarative syntax layer over Swing that can make things a little easier when starting out.

If you want to experiment with Swing, I recommend playing with it in Groovy or BeanShell. It's a real quick to just type:

f=new JFrame("My Frame")
f.setVisible(true)
f.setSize(300,600)

and see your frame show up on the screen. (Both Groovy and Beanshell handle Java syntax very well--it's not like you are not learning Swing--it's more like you are learning it in an interpreter instead of compiler...

By the way, if you don't want to use Java's syntax Groovy can make it easer with statements that are SOMETHING like this (I may have it wrong by just a tad)

f=new JFrame(name="My Frame", visible=true, size=[300,600])

which changes it from 3 or 4 lines down to one.

Bill K
If you think coding Swing GUIs is verbose, you should start thinking of creating your own helper methods/classes.
mklhmnn
@mklhmnn I always do, but I was speaking to someone who seemed like they were pretty new to Java.
Bill K
A: 

I always learn new frameworks best the low-level-way.

  1. Learning a new programming language has proven to be the the best for me if I had to compile source files with the command line. Using an IDE like xCode makes it significant more hard to understand the basics.
  2. I had a very hard way of learning to understand basic concepts of the Eclipse platform, because nearly all tutorials just tell you were to click in the Eclipse GUI. No up-to-date tutorial told what lines to add to what XML file and how the things belong together. Fortunately, this was much simpler for Swing.

Hence my recommendation: don't use a GUI builder for learning, because it hides all the important things which help to really understand what's going on. Use a good Java/Swing tutorial and start typing your applications. After you understand the basics, you can use a GUI builder for prototyping.

mklhmnn