GUI development in Java is very verbose. While trying to build an swing
application I found out it can become a real pain to just lay out your
components. RAD tools a la Delphi could make the process much faster
for a small application. However when the application is growing, RAD
tools can become a problem since their philosophy is more copy and
paste than code reuse.
The most powerful AWT layout is the GridBagLayout, that you very
quickly use everywhere once you master it. However it can become quite
a challenge to write a GridBagLayout that does exactly what you want in
one pass. I found a not so bad utility on the web to help you build
GridBagLayout graphically. But it was not free and had serious
annoyances.
This tool will help you understand the GridBagLayout by allowing you to
interactively build it. Once you have built it you can get the
associated source code. I find it quicker to use this tool than to
write the Java code directly.
You can start the application from here if you have Java Web Start. Or You can download it
from here and then run it using java -jar
easygridbag.jar
Features
Graphical GridBagLayout build tool.
View Java source code associated with the GridBagLayout.
Load and Save Java source code (as beanshell script).
Small API to use the generated beanshell scripts in your code
instead of copying java source. This allows you to modify an existing
layout with EasyGridBag.
Free as in LGPL.
Screenshot
API use example
Use a previously saved layout in your code:
JFrame frame = new JFrame("Example");
JButton button0 = new JButton("button 0"); JButton button1 = new
JButton("button 1");
JButton button2 = new
JButton("button 2"); JButton button3 =
new JButton("button 3");
JButton button4 = new
JButton("button 4"); JButton button5 = new JButton("button
5");
JPanel panel = new JPanel();
panel.add(button0); panel.add(button1); panel.add(button2);
panel.add(button3);
panel.add(button4); panel.add(button5); BshEasyGridBag.getInstance().setGridBagLayout(panel,
Example.class.getResourceAsStream("test.bsh"));
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
Participate
You can report bugs to
. If you make any modification to the code,
I would be glad to hear from you. I can also set up a developer account
on the project if you want to.