I'm using WindowBuilder in Eclipse Indigo to get a handle on the different layouts. Basically I'm just trying to gain a thorough understanding of how each one works and which are best for different scenarios. The below code works, but there are a few things I would like to tweak but I'm not sure how to get my desired effect.
public class Dashboard extends JFrame {
private JPanel contentPane;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Dashboard frame = new Dashboard();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Dashboard() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 602, 372);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel drawingPanel = new JPanel();
drawingPanel.setBounds(6, 6, 487, 251);
contentPane.add(drawingPanel);
drawingPanel.setLayout(null);
JScrollPane propertiesScrollPane = new JScrollPane();
propertiesScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
propertiesScrollPane.setBounds(6, 264, 487, 80);
contentPane.add(propertiesScrollPane);
JPanel selectionPanel = new JPanel();
propertiesScrollPane.setViewportView(selectionPanel);
selectionPanel.setLayout(new BoxLayout(selectionPanel, BoxLayout.X_AXIS));
JPanel surfacesPanel = new JPanel();
selectionPanel.add(surfacesPanel);
surfacesPanel.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
surfacesPanel.setLayout(new BoxLayout(surfacesPanel, BoxLayout.Y_AXIS));
JCheckBox surfaceCheck = new JCheckBox("Visible");
surfaceCheck.setHorizontalAlignment(SwingConstants.CENTER);
surfacesPanel.add(surfaceCheck);
JButton surfaceButton = new JButton("Surfaces");
surfacesPanel.add(surfaceButton);
JPanel spacesPanel = new JPanel();
selectionPanel.add(spacesPanel);
spacesPanel.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
spacesPanel.setLayout(new BoxLayout(spacesPanel, BoxLayout.Y_AXIS));
JCheckBox spacesCheck = new JCheckBox("Visible");
spacesCheck.setHorizontalAlignment(SwingConstants.CENTER);
spacesPanel.add(spacesCheck);
JButton spacesButton = new JButton("Spaces");
spacesPanel.add(spacesButton);
JScrollPane scrollPane_1 = new JScrollPane();
scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane_1.setBounds(504, 6, 92, 251);
contentPane.add(scrollPane_1);
JLabel logoLabel = new JLabel("Logo Here");
LogoLabel.setHorizontalAlignment(SwingConstants.CENTER);
LogoLabel.setBounds(505, 264, 91, 80);
contentPane.add(logoLabel);
}
}
Specifically:
I would like the selectionPanel anchored to the bottom left, the propertiesPanel anchored to the top right, the logoLabel anchored to the bottom right and the drawingPanel anchored to the top left. the idea is that when the main form is resized, the scroll panels and label should stay exactly where they are relative to the edge of the parent form, while the drawingPanel should be resizable horizontally and vertically so that it takes up all the remaining space no matter the size of the top frame. The logo shouldn't be resizable in any dimension, while the selectionPanel should be resizable in the x dimension, and the properties window should be resizable in the y dimension. Lastly, I would like the buttons inside the surfaces and spaces panels to take up the maximum amount of space within the panels. That is to say, without having to do trial and error or specify magic number values, if the panel is 50x50 pixels, and the checkbox is 10 pixels high, then the button should be 40 pixels high.