标签:rgs cto extends 多个 contain tar info nbsp out
容器中可以有多个JPanel面板,一个JPanel面板中可以有多个控件。
滚动面板 JScrollPane中只能有一个控件。
public class Demo extends JFrame { public Demo() { setBounds(100, 100, 600, 200); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new GridLayout(1, 2, 10, 10)); //创建2个面板 JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(1, 3)); JPanel p2 = new JPanel(new BorderLayout()); p2.setBackground(Color.BLUE); //设置面板边框,标题 p1.setBorder(BorderFactory.createTitledBorder("面板1")); p2.setBorder(BorderFactory.createTitledBorder("面板2")); p1.add(new JButton("b1")); p1.add(new JButton("b1")); p1.add(new JButton("b1")); p1.add(new JButton("b1")); p2.add(new JButton("b2"), BorderLayout.EAST); p2.add(new JButton("b2"), BorderLayout.WEST); p2.add(new JButton("b2"), BorderLayout.SOUTH); p2.add(new JButton("b2"), BorderLayout.NORTH); p2.add(new JButton("b2")); c.add(p1); c.add(p2); setVisible(true); } public static void main(String[] args) { new Demo(); } }
public class Demo extends JFrame { public Demo() { setBounds(100, 100, 200, 100); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Container c = getContentPane(); JTextArea area=new JTextArea();//文本域 JScrollPane sp=new JScrollPane(area);//将文本域添加到滚动面板中 c.add(sp); setVisible(true); } public static void main(String[] args) { new Demo(); } }
标签:rgs cto extends 多个 contain tar info nbsp out
原文地址:https://www.cnblogs.com/xixixing/p/9451822.html