Design Java UI Like Visual Basic

One of the most frustrating and time-consuming tasks in Java is creating basic, boring, ordinary UI.  As in, windows, buttons, scroll bars, text fields, etc.

This is in stark contrast to, say, Visual Basic, where you can just drag and drop elements onto a form, and what you see is what you get.  In Java, if you want anything other than just the basics, you're going to have to do a lot of typing.

That is, unless, you are using the WindowBuilder Engine and Eclipse.

  • In Eclipse (3.7 at time of this writing), go to Help -> Install New Software.
  • Enter this address:
  • Download everything listed, then restart Eclipse:

After this, right-click in your project's src folder to create a new item.  Chose "other", then select the "Application Window" under Window Builder->Swing Designer:

Open the file you've created, and notice something cool-- you now have a "design" tab at the bottom of the code window.  Click it.  You now see a screen like so:

Notice it now looks a great deal like Visual Basic?

But, there's a quick step I'd recommend you take before you start dragging and dropping.

Go to Windiw -> Preferences -> WindowBuilder -> Swing -> Code Generation -> Event Handlers.

  • Check the box that says "Create stub event handler methods named:" and select "handle_.... whatever you want".  Hit OK and return to your screen.
  • This makes it so that when a user clicks on a button (or some other interactive element) a separate method is called.  I personally just happen to like that.

Back to the main "design" screen.  If you click "Absolute Layout", then click your window (to add it), you can then click JButton and click the window to place a button or two.  Like so:

Now here's the cool part:  double-click on one of the buttons.  You are then taken to the code (just like in Visual Basic) where you can then code what to do when that button is clicked:

Pretty cool, eh?

There's lots of other neat things this system can do, but I don't have the space to explain them all.