I couldn’t resist reading an
article opening with "I want to break free from the GridBagLayout:
introducing Jaxx".
I should have known better…
Here is the value proposition of Jaxx: you describe your Swing
applications in XML and you code your Java logic inside these XML files.
Yup.
I have two problems with this:
- Jaxx does nothing to rid your of GridBagLayout. If you
need complex layouts and you want to stick with the javax.swing
packages, GridBagLayout is your only hope.
- Java code in… XML files? Now that’s a great idea.
Java developers are finally getting hooked to IDE’s and Jaxx offers to take
these away from us. No more refactoring, no more completion, awkward
formatting… Now that’s a winner.
I understand the value of describing interfaces in an XML file, but at least,
please make sure that I can keep writing my logic in good old Java files.
As for GridBagLayout, do yourself a favor and forget everything you
ever learned about it. Either use
JGoodies or SWT’s fantastic
GridLayout.
#1 by Romain Guy on March 30, 2006 - 11:30 am
Or better yet, use a GUI builder 🙂
#2 by Alexis MP on March 30, 2006 - 11:33 am
I must admit that sometimes I feel like I’m not giving all technologies a fair coverage when I blog… but afterall I’m no journalist trying to be fair to all (assuming that’s what journalists do).
Reading your post which fails to mention javax.swing.GroupLayout has me feel much better C
#3 by Keith Lea on March 30, 2006 - 4:24 pm
Cedric, I think the main attraction of JAXX is use of CSS. I see this as a huge innovation. Maybe XML isn’t the right application of CSS, but I think using CSS to design rich applications is an awesome idea.
#4 by Jesse Kuhnert on March 30, 2006 - 7:21 pm
Surely you gest? Use an html markup construct to describe how to render a GUI?
I can’t tell you how many endless miles of torturous swing code I’ve written using GridBagF-out. I don’t know why rendering hints weren’t added in in the beggining. Maybe the sun engineers were too busy mentally masturbating each other to check out what more of the tried and true GUI toolkits were doing. (like Qt, which I love…even though c++ is dying on us 🙂 )
#5 by Brian Slesinsky on March 30, 2006 - 10:20 pm
I think it’s a bad idea that will unfortunately be popular, for the same reasons that JSP’s, XOM, and embedding JavaScript into HTML are popular. The people who want this sort of thing don’t care about easy testing or refactoring. It’s sure to keep IDE developers employed for years to come.
#6 by 锡达蜂窝 on March 31, 2006 - 12:28 am
锡达蜂窝
蜂窝纸板设备
蜂窝纸板机械
#7 by Lee Meador on March 31, 2006 - 11:10 am
I’m not going to comment on replacing Swing with HTML/CSS. Both have their place.
If you use Swing too little to figure out the “art” of GridBagLayout and you don’t want to use one of the open source layouts, you can just figure out how to nest the simpler layouts to make it work.
Second, quit worrying about the “exact” layout of the thing. Even if you are tied to Windows, in 3 years the new screen resolutions in common use will make todays eye candy into a pain in the eye unless you plan for inexact placement. That’s assuming you don’t want your Swing app to run today on some Linux windowing system or Mac where the fonts are all different. (And we don’t want to think about what might change in the next version of Java.)
By “nesting” above I mean you put panels inside panels. The outer panel might be using a grid layout with one column while the inner panel uses a box layout that’s horizontal. If you think about it and group the components intelligently, you can do almost anything in a way that scales well and accounts for the fickleness of font sizes.
A “rule” for making good layouts is to never make anything a fixed size in pixels other than the margins. Let boxes be their natural size. Maybe give the user a choice of font size and make all the fonts with multiples of that size. Otherwise just let fonts be whatever size they want. That allows adjusting to different display devices.
#8 by Ross Judson on March 31, 2006 - 7:48 pm
Goodness. I never quite understand why the nesting nature of XML generates such attention for UI creation. Here’s how I build UI in Java…this is whole thing. Reflection is used to create nested component structures and wire up listeners. Annotations guide the process. Small inferences eliminate the need for much boilterplate. If you think this is dense, you should see the Scala code 🙂
public class PipeUI extends PipeLogic
{
PipeConnection connection;
ObjectName probeName;
States appState = States.Initial;
long connectionBegan = System.currentTimeMillis();
@Skip JSVGCanvas svgCanvas;
@Skip JPanel homeChartPanel;
@Skip LogPanel logPanel;
@Skip JList spaceList;
@Border(NORTH) @Empty
JRibbon ribbon = buildRibbon();
@Border(CENTER) @Empty
JPanel cardPanel = new JPanel() {
@Card(“Home”)
JPanel hc = homeChartPanel = new JPanel();
@Card(“Log”)
LogPanel lp = logPanel = new LogPanel();
@Card(“Workspace”) @Transparent
JPanel workspace = new JPanel() {
@Border(WEST) @Titled(“Workspaces”)
JPanel spacePanel = new JPanel() {
JScrollPane slPanel = new JScrollPane() {
JList sl = spaceList = new JList();
};
};
@Border(CENTER) @Titled(“Workspace: Default”)
JScrollPane workScroll = new JScrollPane() {
@Trues({“antiAliased”, “gridEnabled”, “gridVisible”})
JGraph workDisplay = new JGraph();
};
};
@Card(“Display”) @Transparent
JPanel display = new JPanel() {
@Border(CENTER) @Transparent
JSVGCanvas svg = svgCanvas = new JSVGCanvas();
};
};
@Border(SOUTH) @Flow(align=LEFT)
JPanel statusBar = new JPanel() {
@Etched JLabel about = new JLabel(“Pipeline v0.1 (c) 2006 Soletta”);
@Etched JLabel time = new JLabel(“”);
@Etched JLabel connected = new JLabel(“”);
JButton disconnect = new JButton(“Disconnect”) {
public void actionPerformed(ActionEvent e) {
JOptionPane.showConfirmDialog(PipeUI.this, “Are you sure you want to disconnect?”);
}
};
Timer timer = new LocalTimer(1000) {
DateFormat df = DateFormat.getDateTimeInstance();
public void actionPerformed(ActionEvent e) {
time.setText(df.format(new Date()));
connected.setText(appState.toString() + ” since ” + df.format(new Date(connectionBegan)));
}};
};
#9 by Ross Judson on March 31, 2006 - 7:49 pm
p.s. what you’re missing there is the indentation, of course 🙂 put it in Eclipse and format it.
#10 by Brad Reynolds on April 4, 2006 - 6:06 am
I think you meant GridLayout and not TableLayout for SWT. TableLayout is just for Tables.
#11 by Richard Rodger on April 6, 2006 - 4:09 am
Ah, the joys of code generation. Sounds like this is what Jaxx is doing. I’ve learned through bitter experience that you *never* put Java code anywhere except in a .java file. Oh My. What a world of pain…
#12 by oyun on December 28, 2007 - 9:39 am
Thanks