解决方法
您必须将按钮添加到另一个面板,然后将该面板添加到框架.
事实证明,BorderLayout扩展了组件中间的东西
您的代码现在应该如下所示:
之前
public static void main( String [] args ) { JLabel label = new JLabel("Some info"); JButton button = new JButton("Ok"); JFrame frame = ... frame.add( label,BorderLayout.NORTH ); frame.add( button,BorderLayout.CENTER ); .... }
将其更改为以下内容:
public static void main( String [] args ) { JLabel label = new JLabel("Some info"); JButton button = new JButton("Ok"); JPanel panel = new JPanel(); panel.add( button ); JFrame frame = ... frame.add( label,BorderLayout.NORTH ); frame.add( panel,BorderLayout.CENTER); .... }
前/后
Before http://img372.imageshack.us/img372/2860/beforedl1.png
After http://img508.imageshack.us/img508/341/aftergq7.png