zoukankan      html  css  js  c++  java
  • 面板 JPanel,滚动面板 JScrollPane,文本域JTextArea

    容器中可以有多个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();
        }
    }
  • 相关阅读:
    第二阶段团队站立会议06
    第二阶段团队站立会议05
    Spring
    JVM
    线程池
    java内存模型
    线程
    接口与抽象类
    动态绑定,多态,static
    同步异步,并发并行概念的理解
  • 原文地址:https://www.cnblogs.com/xixixing/p/9451822.html
Copyright © 2011-2022 走看看