views:

850

answers:

7

I've been working with Java GUI for a while now but the whole model/structure of JFrames, paint(), super, etc is all murky in my mind. I need a clear explanation or link that will explain how the whole GUI system is organized.

stackoverflow-ers: can you help me?


Thanks everyone, some more answers would be better but this is great!

+2  A: 

Have you looked at the Java Swing Tutorial (click here)? It does a pretty good job of covering the basics of developing Swing applications.

Elie
+7  A: 

Mmhh yeah.. The same happened to me. Actually until this day I don't quite get 100% how all it works.

Swing is a very flexible framework. Perhaps too flexible. With flexibility comes a lot of abstraction and with abstraction .. well. :)

I've found the following article worth reading. It help me to understand better the big picture of Swing.

http://java.sun.com/products/jfc/tsc/articles/architecture/

http://java.sun.com/products/jfc/tsc/articles/architecture/ui_install/index.html

It explains quite well how the model and the delegate works. It always drive me mad when I see those JLabel LabelUI and ui.update etc.

I hope this helps.

OscarRyz
Very useful link - had not seen that before; bookmarked for a closer look later.
Software Monkey
Yeahh ... I don't remember how I came to that link. I didn't found it until after several years. I don't know the "google search" to produce it either, so I have it in my bookmarks too.
OscarRyz
A: 

Filthy Rich Clients by Chet Haase and Romain Guy is a great book about Java UI. It covers some more advanced stuff too, but introduction and few first chapters explain fundamental things well.

GvS
A: 

If, after reading the Swing tutorial, you find your interest lies in more advanced topics, you may also wish to look at Swing Second Edition by Robinson and Vorobiev.

Paul Brinkley
+2  A: 

Since this question is tagged with JFrame, I'll suggest a few links for understanding how JFrames and other top-level Swing containers work.

I also found that Swing was (and still is) quite involved and taking a look at the documentation provided by Sun is required every once in a while -- Every time I check, I seem to learn something new.

First, the basics: JFrame class from the Java API Specifications. The Java API Specifications often provide good detailed information about the classes. In this instance, you'll notice that there are several links such as How to Make Frames section from The Java Tutorials.

Aside from that, I'll also recommend looking at the Lesson: Using Swing Components from The Java Tutorials. The lesson provides instructions on how to use the components provided in Swing along with some useful examples.

For more specifics parts that I've found confusing when I started with Swing was all the different types of panes, such as the ContentPane, RootPane, GlassPane. The Using Top-Level Containers section provides information and helpful diagrams on the container hierarchy of the top-level containers. The How to Use Root Panes section gets into the details about the Glass, Layered, and Content Panes with plenty of examples.

coobird
A: 

I've found that simply browsing around in the source code (ctrl-click on a name if you're using NetBeans) has been really helpful. If I see a method appear in the completion dialog that I'm not familiar with, I'll just click "Go to source" and look around until I'm comfortable with it.

Michael Myers
+1  A: 

I found Swing Explorer to be a precious tool to understand the hierarchy of components (particularly in complex GUIs) and look at properties (alas, read-only: we get used to Firebug convenience!). It has an Eclipse plugin.

PhiLho