java,枯燥中遇见美丽JFrame,窗体(面板,JPanel)
Posted 逐梦武威
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java,枯燥中遇见美丽JFrame,窗体(面板,JPanel)相关的知识,希望对你有一定的参考价值。
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)的主要内容,如果未能解决你的问题,请参考以下文章
在学习枯燥的Java中遇见美丽的Jframe,窗体中的单选按钮(JRadioButton)