我正在尝试完成此布局: http: //www.domizai.ch/tmp/targetLayout.jpg
但我现在得到的是:http: //www.domizai.ch/tmp/layoutNow.jpg
我只是希望 panel2 将其在中心 y 对齐,而不是将其拉伸到 panel1 的高度。
我的代码现在看起来像这样:
JPanel panel1 = new JPanel();
panel1.add(new JLabel(icon,JLabel.CENTER));
panel1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 20));
JPanel panel2 = new JPanel();
panel2.setLayout(new BorderLayout());
panel2.add(new JLabel("Copy files to Desktop..."),BorderLayout.NORTH);
panel2.add(bar,BorderLayout.CENTER);
panel2.add(label = new JLabel("1 minute remaining");,BorderLayout.SOUTH);
JPanel panel3 = new JPanel();
panel3.setLayout(new BorderLayout());
panel3.add(panel1,BorderLayout.WEST);
panel3.add(panel2,BorderLayout.EAST);
JPanel panel4 = new JPanel();
panel4.setLayout(new BorderLayout());
panel4.add(new JLabel(),BorderLayout.LINE_START);
panel4.add(button,BorderLayout.LINE_END);
panel4.setBorder(BorderFactory.createEmptyBorder(10,0, 0, 0));
JPanel panel5 = new JPanel();
panel5.setLayout(new BorderLayout());
panel5.add(panel3, BorderLayout.PAGE_START);
panel5.add(panel4, BorderLayout.PAGE_END);
panel5.setBorder(BorderFactory.createEmptyBorder(20,20, 10, 20)); // top, left bottom, right
frame.setContentPane(panel5);
最好的方法是什么?谢谢!