码迷,mamicode.com
首页 > 编程语言 > 详细

java,枯燥中遇见美丽JFrame,窗体(面板,JPanel)

时间:2018-12-09 21:29:59      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:constant   分享   layout   布局   tcl   nta   get   highlight   vax   

package com.company;

import javax.swing.*;
import java.awt.*;

public class Main extends JFrame {//JPanel面板
    public Main(){
        setBounds(100,100,500,300);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container c=getContentPane();
        c.setLayout(new GridLayout(2,2,10,10));

        JPanel p1=new JPanel();
        p1.setLayout(new GridLayout(1,3,10,10));
        JPanel p2=new JPanel(new BorderLayout());
        JPanel p3=new JPanel(new GridLayout(1,2,10,10));
        JPanel p4=new JPanel(new GridLayout(2,1,10,10));
        /*
        添加布局
         */
        p1.setBorder(BorderFactory.createTitledBorder("面板1"));
        p2.setBorder(BorderFactory.createTitledBorder("面板2"));
        p3.setBorder(BorderFactory.createTitledBorder("面板3"));
        p4.setBorder(BorderFactory.createTitledBorder("面板4"));

        p1.add(new JButton("p1"));
        p1.add(new JButton("p1"));
        p1.add(new JButton("p1"));
        p1.add(new JButton("p1"));

        p2.add(new JButton("p2"),BorderLayout.CENTER);
        p2.add(new JButton("p2"),BorderLayout.SOUTH);
        p2.add(new JButton("p2"),BorderLayout.WEST);
        p2.add(new JButton("p2"),BorderLayout.NORTH);
        p2.add(new JButton("p2"),BorderLayout.EAST);

        p3.add(new JButton("p3") );
        p3.add(new JButton("p3") );

        p4.add(new JButton("p4") );
        p4.add(new JButton("p4") );


        c.add(p1);c.add(p2);c.add(p3);c.add(p4);
        setVisible(true);
    }

    public static void main(String[] args) {
        new Main();
	// write your code here
    }
}

 技术分享图片

 

java,枯燥中遇见美丽JFrame,窗体(面板,JPanel)

标签:constant   分享   layout   布局   tcl   nta   get   highlight   vax   

原文地址:https://www.cnblogs.com/llhhcc/p/10093293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!