File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes A big GUI question.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "A big GUI question...." Watch "A big GUI question...." New topic

A big GUI question....

Ryan Smith
Ranch Hand

Joined: Jun 29, 2004
Posts: 40
I'm not sure if this is exactly a's pretty big.

Anyways, I'm designing a GUI interface; my previous experience has been with more GUI-based languages, such as VB and RealBasic. I'm having some trouble getting my interface to look exactly how I want it. Right now all I've got is a FlowLayout() and that is just not doing it. What are some basic methods that I could use to order all of the buttons/JTextFields/drop-down menus/whatever in my JFrame? I know this isn't very specific...sorry!
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

FlowLayout puts everything in a line, so yeah, that's only going to get you so far!

There are two basic ways you can go: GridBagLayout, or nested simple layouts.

The GridBagLayout layout manager can do anything. It's really complicated, though, and you can spend forever and a day getting everything just so. But one GridBagLayout could be used to layout dozens of components in a single container in an almost arbitrarily complex arrangement.

The other way to go is to use many nested containers and multiple layout managers. Use one JPanel with a row of buttons in it using a FlowLayout. Add that JPanel to the bottom of a JFrame which uses the BorderLayout. In the center of that JFrame, add another JPanel using a GridLayout. And so on. You can build up complex arrangements like this one piece at a time.

Personally, I do the latter. I like building things up incrementally.

Finally, there are indeed IDEs with GUI-builders that let you draw your interface. These are generally frowned upon by Swing afficianados, but they do exist.

[Jess in Action][AskingGoodQuestions]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum, where they love to get messy with this GUI stuff...

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

I have to say that IntelliJ IDEA 4.0 has a GUI builder that allows me to bypass the layouts and get everything "just so" by clicking and dragging. It was easy to learn and allows you to add custom controls for easy reuse.

The drawback, of course, is that if you open one of my .java files in a text editor, it isn't very pretty, but I have saved weeks and probably years off of my life by using the GUI builder and that makes it worth it to me.
I agree. Here's the link:
subject: A big GUI question....
It's not a secret anymore!