I have been trying to modify the contents of a gridlayouts in a panel i created(Java by the way Ecliplse), but no method ive tried is working this is the code:
// Planning to add about 6 more buttons to complete calculator set.
JPanel panel = new JPanel(new GridLayout(4, 4));
panel.setBounds(0, 150, 400, 500);
panel.setBackground(Color.GRAY);
frame.add(panel);
JButton b1 = new JButton("1");
JButton b2 = new JButton("2");
JButton b3 = new JButton("3");
JButton b4 = new JButton("4");
JButton b5 = new JButton("5");
JButton b6 = new JButton("6");
JButton b7 = new JButton("7");
JButton b8 = new JButton("8");
JButton b9 = new JButton("9");
JButton b10 = new JButton("10");
// Add buttons to the panel
panel.add(b1);
panel.add(b2);
panel.add(b3);
panel.add(b4);
panel.add(b5);
panel.add(b6);
panel.add(b7);
panel.add(b8);
panel.add(b9);
panel.add(b10);
// Tried this but it did not work.
Dimension buttonSize = new Dimension(25, 25);
b1.setPreferredSize(buttonSize);
b2.setPreferredSize(buttonSize);
b3.setPreferredSize(buttonSize);
b4.setPreferredSize(buttonSize);
b5.setPreferredSize(buttonSize);
b6.setPreferredSize(buttonSize);
b7.setPreferredSize(buttonSize);
b8.setPreferredSize(buttonSize);
b9.setPreferredSize(buttonSize);
b10.setPreferredSize(buttonSize);
I just want to reduce the size of the buttons.
camickr
325k21 gold badges174 silver badges293 bronze badges
lang-java
GridLayoutwith regards to sizing