Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A big GUI question....

 
Ryan Smith
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this is exactly a question...it'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
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum, where they love to get messy with this GUI stuff...
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic