Java Reference
In-Depth Information
constraints.insets = new Insets(0, 0, 0, 0);
frame.add(buttons.get("0"), constraints);
constraints.insets = new Insets(0, 10, 0, 0);
constraints.gridy = 2;
frame.add(buttons.get("C"), constraints);
constraints.gridy = 3;
frame.add(buttons.get("="), constraints);
frame.pack();
frame.setVisible(true);
}
private static Map<String, JButton> makeButtons(String... strings) {
Map<String, JButton> buttons = new HashMap<>();
for (String label : strings)
buttons.put(label, new JButton(label));
return buttons;
}
}
2.
Run the project from Eclipse. You should see the window in Figure 11-14.
3.
Try resizing the window. Observe how the components stretch and behave.
figure 11-14  
How It Works
This is how it works:
1.
This class is similar to the previous one, but a GridBagLayout object is now specified as the layout
manager.
Search WWH ::




Custom Search