java复杂布局_Java复杂GUI布局举例与源码

【举例要求】要求完成下图中要求的布局,形式要求一致,并且要求美观。这里使用的布局较多,比较复杂,编写好的源码与大家分享一下。

0818b9ca8b590ca3270a3433284dd417.png

package ComPlexPanel;

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.GridLayout;

import javax.swing.ButtonGroup;

import javax.swing.JButton;

import javax.swing.JCheckBox;

import javax.swing.JComboBox;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JRadioButton;

import javax.swing.JTextArea;

public class ComPlexPanel {

JFrame frame = new JFrame("ComPlexPanelDemo Made By HY49");

Container content = frame.getContentPane();

public ComPlexPanel(){

JPanel GrandParentPanel = new JPanel();

// JPanel FatherPanel = new JPanel();

JPanel MotherPanel = new JPanel(new GridLayout(4,1));

JPanel BrotherPanel01 = new JPanel();

JPanel BrotherPanel02 = new JPanel(new GridLayout(1,5));

JPanel BrotherPanel03 = new JPanel();

JPanel SonPanel01 = new JPanel();

JTextArea area01 = new JTextArea(6,5);

SonPanel01.add(area01);

JPanel SonPanel02 = new JPanel(new GridLayout(3,1));

JPanel SonPanel03 = new JPanel();

JTextArea area02 = new JTextArea(6,5);

SonPanel03.add(area02);

JPanel SonPanel04 = new JPanel(new GridLayout(3,1));

JPanel SonPanel05 = new JPanel();

JTextArea area03 = new JTextArea(6,5);

SonPanel05.add(area03);

JButton OKButton = new JButton("OK");

JButton CancleButton = new JButton("Cancle");

JButton SetupButton = new JButton("SetUp");

JButton HelpButton = new JButton("Help");

MotherPanel.add(OKButton);

MotherPanel.add(CancleButton);

MotherPanel.add(SetupButton);

MotherPanel.add(HelpButton);

JLabel label01= new JLabel("Demo: ComPlexPanelDemo",JLabel.CENTER);

BrotherPanel01.add(label01);

JLabel label02 = new JLabel("Priority: ");

String[] Priority = {"High","Middle","Low"};

JComboBox comboBox = new JComboBox(Priority);

comboBox.setEditable(false);

comboBox.setSelectedItem("High");

JCheckBox checkBox = new JCheckBox("Print to File");

BrotherPanel03.add(label02);

BrotherPanel03.add(comboBox);

BrotherPanel03.add(checkBox);

JCheckBox checkBox01 = new JCheckBox("Image");

JCheckBox checkBox02 = new JCheckBox("Text");

JCheckBox checkBox03 = new JCheckBox("Code");

SonPanel02.add(checkBox01);

SonPanel02.add(checkBox02);

SonPanel02.add(checkBox03);

ButtonGroup buttonGroup = new ButtonGroup();

JRadioButton radioButton01 = new JRadioButton("Selection");

buttonGroup.add(radioButton01);

JRadioButton radioButton02 = new JRadioButton("All");

radioButton02.setSelected(true);

buttonGroup.add(radioButton02);

JRadioButton radioButton03 = new JRadioButton("Applet");

buttonGroup.add(radioButton03);

SonPanel04.add(radioButton01);

SonPanel04.add(radioButton02);

SonPanel04.add(radioButton03);

SonPanel04.setSize(30, 50);

BrotherPanel02.add(SonPanel01);

BrotherPanel02.add(SonPanel02);

BrotherPanel02.add(SonPanel03);

BrotherPanel02.add(SonPanel04);

BrotherPanel02.add(SonPanel05);

GrandParentPanel.add(BrotherPanel01,BorderLayout.NORTH);

GrandParentPanel.add(BrotherPanel02,BorderLayout.CENTER);

GrandParentPanel.add(MotherPanel,BorderLayout.EAST);

GrandParentPanel.add(BrotherPanel03,BorderLayout.SOUTH);

content.add(GrandParentPanel);

frame.setVisible(true);

frame.setBounds(450, 200, 490, 260);

// frame.pack();

}

public static void main(String[] args) {

// TODO Auto-generated method stub

new ComPlexPanel();

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值