我需要在一个空白的JPanel的右下角放一个按钮
+-----------------------------------+ | | | | | | | | | | | | | | | | | +-----------+| | | Click Me! || | +-----------+| +-----------------------------------+
我怎么做?应该很容易吗?我想找到正确的布局管理器,而不是使用一系列嵌套面板.
JPanel panel = new JPanel(); panel.setLayout(new SomeKindOfLayoutManagerThatDoesThis()); panel.add(new JButton("Click Me!"),SETTINGS);
解决方法
我建议使用带有流布局的边框布局管理器.
就像是:
this.setLayout(new BorderLayout()); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); JButton clickmeButton = new JButton("Click Me"); buttonPanel.add(clickmeButton); this.add(buttonPanel,BorderLayout.SOUTH);