• Share this article:

Visual Editor, Swing, and GridBagLayout

Thursday, May 4, 2006 - 22:32 by Wayne Beaton

I’ve been using the Visual Editor to build some user interfaces for an Eclipse application that I’m building. As a distraction, I thought it might be fun to spend a few minutes cobbling together a Swing JFrame (okay, maybe “fun” isn’t the right word).

Below is what it looks like in the editor:

At the point I took the screen shot, I was about to drop a new JLabel between the two already placed ones. The “03” by the cursor is feedback indicating that I’m about to drop the widget at position x=0, y=3. The form itself is pretty simple: just a bunch of JLabels and JTextFields. The JTextArea is in a JScrollPane and I threw in the slider for kicks. The two push buttons at the bottom are in a nested JPanel with a FlowLayout layout.

I’ve always hated using the GridBagLayout; it’s just too weird and complex for my little brain. But Visual Editor makes it a lot easier (the grid lines make it a lot easier). I managed to put this example together in about five minutes. My little brain can handle that…