i 绝望

依然

Miss Lang

java图形用户界面BorderLayout布局。冲突

总结:在使用边界布局发现,把所有的按钮组件都放入了panel.但是在中部的按钮组件找不到了。发现自己重复用了组件

 

1.this.add(bt4,BorderLayout.North);

2.panel.add(bt4,BorderLayout.North);

this.add(panel);

这里的1和2的不同点是,前者直接放在frame里。

后者是放在面板里,但是它会造成按钮组件根本看不到

package clientFrame;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JFrame;

public class Bian extends JFrame {
	JPanel panel;
	JButton bt1, bt2, bt3, bt4, bt5;

	public Bian() {
		bt1 = new JButton("确定");
		bt2 = new JButton("取消");
		bt3 = new JButton("退");
		bt4 = new JButton("选择");
		bt5 = new JButton("哈哈哈");
		// 开始布局
		this.getContentPane().setBackground(Color.red);
		panel = new JPanel();
		this.add(bt1, BorderLayout.NORTH);
		// panel.add(bt2,BorderLayout.SOUTH);//不长脑子,不知道自己要达到什么目的,怎么写》全错误,怎么能把按钮都放进同一个panel里面,
		this.add(bt1, BorderLayout.EAST);
		this.add(bt2, BorderLayout.WEST);
		this.add(bt3, BorderLayout.NORTH);
		this.add(bt4, BorderLayout.SOUTH);
		this.add(bt5, BorderLayout.CENTER);
		// this.add(panel);你妹,记住前面用了 this.后面就不需要用add(panel)这样导致中部的按钮组件无法显示
		this.setVisible(true);
		this.setSize(599, 490);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}

	public static void main(String[] args) {
		Bian b = new Bian();
	}
}

  

 

 

 

 

 

 

 

posted on 2013-11-30 22:16  juewang  阅读(755)  评论(0编辑  收藏  举报

绝望依然

Miss Lang