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?
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.