垂直方向の上揃えのレイアウトを機能させようとしています。これは私が持っているものです:
JPanel pane = new JPanel();
pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
MyImagePanel panelImage = new MyImagePanel();
panelImage.setSize(400, 400);
pane.add(new JComboBox());
pane.add(panelImage);
pane.add(new JButton("1"));
pane.add(new JButton("2"));
pane.add(new JButton("3"));
JFrame frame = new JFrame("Title");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600);
frame.add(pane);
frame.pack();
frame.setVisible(true);
すべてのコントロールが表示されますが、実行時に上部と下部の間にパディングが適用されているように見えるため、垂直方向にやや中央揃えになっています。これは私がしようとしていることです:
-----------------------------------------------------
| ComboBox |                                        |
------------                                        |
|          |                                        |
| Image    |                                        |
|          |                                        |
------------                                        |
| Button 1 | Any additional space fills the right   |
------------                                        |
| Button 2 |                                        |
------------                                        |
| Button 3 |                                        |
------------                                        |
|                                                   |
|  Any additional space fills the bottom            |
|                                                   |
-----------------------------------------------------
BoxLayoutにそれをさせるにはどうすればよいですか?
ありがとう
- - - - - - - - - - - - - アップデート - - - - - - - - - - - - -
これを使用できました:
Box vertical = Box.createVerticalBox();
frame.add(vertical, BorderLayout.NORTH);
vertical.add(new JComboBox());
vertical.add(new JButton("1"));  
...
欲しかったものを手に入れるために。