How should I go about building this UI using Java Swing without the use of GUI Builders?
I don't need a solution but just some general guidance on how to get started with this. Specifically, cues on selecting the best layout(s) and Swing components to complete the job.
What I have done so far is build a JFrame with label, text field pairs like so:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
class AdminForm {
AdminForm() {
JFrame f = new JFrame("Panel Example");
JPanel gui = new JPanel(new BorderLayout(2,2));
JPanel labelFields = new JPanel(new BorderLayout(2,2));
labelFields.setBorder(new TitledBorder("BorderLayout"));
JPanel labels = new JPanel(new GridLayout(0,2,1,1));
labels.setBorder(new TitledBorder("GridLayout"));
JPanel fields = new JPanel(new GridLayout(0,2,1,1));
fields.setBorder(new TitledBorder("GridLayout"));
for (int ii=1; ii<8; ii++) {
labels.add(new JLabel("Label " + ii));
// if these were of different size, it would be necessary to
// constrain them using another panel
labels.add(new JTextField(10));
}
labelFields.add(labels, BorderLayout.CENTER);
//labelFields.add(fields, BorderLayout.EAST);
gui.add(labelFields, BorderLayout.NORTH);
//gui.add(guiCenter, BorderLayout.CENTER);
f.add(gui);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static void main(String[] args) throws Exception {
//Create the GUI on the event dispatching thread
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
new AdminForm();
}
});
}
}
Concerns:
I'm not sure I used the best layout configuration to get the labels and the text fields list in place. A better way to do this?
The panel is shrunk when I run this. I think I need to specify a panel size?
I need another panel to the right of this obviously. How do I introduce a new panel and get this aligned with what I already have?


GridBagLayoutis the most versatile and tunable layout manager - but it's hard to understand and the learning curve is steep