Hi Aaron,

If all you want is a simple dynamic UI there's no need to overcomplicate things... below is a self-contained, executable Swing example of arbitrarily placing some components on a form. Of course some people might say that anything Swing is overcomplicated, but I'm a fan so what the heck. This example may not demonstrate best practices in Swing, but if it's results you're after then this may be right up your alley. (Please disregard the JFormDesigner stuff... that's just me cheating.)


- - -

import java.awt.*;
import javax.swing.*;

public class NullLayoutDemo extends JPanel

public NullLayoutDemo()

private void initComponents()
// JFormDesigner - Component initialization - DO NOT MODIFY // GEN-BEGIN:initComponents
label2 = new JLabel();
label3 = new JLabel();
textField1 = new JTextField();
comboBox1 = new JComboBox();
button1 = new JButton();

//======== this ========

//---- label2 ----
label2.setText("Field 1");
label2.setBounds(new Rectangle(new Point(15, 20), label2.getPreferredSize()));

//---- label3 ----
label3.setText("Field 2");
label3.setBounds(new Rectangle(new Point(15, 55), label3.getPreferredSize()));
textField1.setBounds(70, 14, 140, textField1.getPreferredSize().height);
comboBox1.setBounds(70, 50, 140, comboBox1.getPreferredSize().height);

//---- button1 ----
button1.setBounds(new Rectangle(new Point(126, 85), button1.getPreferredSize()));

setPreferredSize(new Dimension(225, 125));
// JFormDesigner - End of component initialization //GEN- END:initComponents

// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN- BEGIN:variables
private JLabel label2;
private JLabel label3;
private JTextField textField1;
private JComboBox comboBox1;
private JButton button1;
// JFormDesigner - End of variables declaration //GEN-END:variables

public static void main(String[] args)
JFrame frame = new JFrame("Null Layout Demo");
frame.setContentPane(new NullLayoutDemo());


On 20-Feb-2008, at 6:45 PM, Thorbjørn Ravn Andersen wrote:

Aaron Bartell skrev den 20-02-2008 22:38:
Could you elaborate on what you mean by "drawing the screen dynamically"?

I get an XML feed from the server and it will have something like the

<form id="form1">
<button id="btnSubmit" x="12" y="100" value="Submit" />

Based on that I know I need to display a form with a single button on the
screen which I do by parsing the XML and incrementally "drawing it" by
instantiating AWT objects and adding them to a panel/frame.

The snippet looks very close to something HTML'ish, so perhaps you could
use an XSLT-stylesheet to create HTML you could use in a web page? The
logic for that is very simple.

It all depends on how much functionality and speed you need.


This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.

This thread ...


Return to Archive home page | Return to MIDRANGE.COM home page