Reputation: 13
I have a very big problem. I need to do vertical menu in the center of window. What could be easier? What I did:
JFrame
and set BorderLayout
to it:
JFrame jfr = new JFrame("Frame");
JButton b1 = new JButton("b1");
JButton b2 = new JButton("b2");
JButton b3 = new JButton("b3");
JButton b4 = new JButton("b4");
JPanel jpan = new JPanel();
jpan.setLayout(new BoxLayout(jpan, BoxLayout.Y_AXIS));
jpan.add(b1);
jpan.add(b2);
jpan.add(b3);
jpan.add(b4);
b1.setAlignmentX(JComponent.CENTER_ALIGNMENT);
b2.setAlignmentX(JComponent.CENTER_ALIGNMENT);
b3.setAlignmentX(JComponent.CENTER_ALIGNMENT);
b4.setAlignmentX(JComponent.CENTER_ALIGNMENT);
JFrame
jfr.add(jpan, BorderLayout.CENTER);
Please help me to understand this layouts! Only say like this: "You should use this, when you use this layout" And now main question: How can I change size of buttons?
Upvotes: 1
Views: 68
Reputation: 168845
There are a number of easy ways to change the size of buttons:
Given the last is quite arbitrary, here is a demonstration of the first 3 techniques:
Upvotes: 1