LayoutDemo

 

package swing.ui;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/*2015-7-10*/
public class PanelLayoutTest extends JFrame {
    private static final long serialVersionUID = -2298874328963807208L;

    private JTextField
            name = new JTextField(),
            id = new JTextField();

    private JTextArea content = new JTextArea();

    public PanelLayoutTest() {
        this.setTitle("LayoutTest");
        this.setSize(600, 300);
        JPanel northPanel = new JPanel();
        northPanel.setLayout(new GridLayout(2, 2));
        northPanel.add(new JLabel("ID:"));
        northPanel.add(name);
        northPanel.add(new JLabel("Name:"));
        northPanel.add(id);

        this.add(northPanel, BorderLayout.NORTH);
        this.add(new JScrollPane(content), BorderLayout.CENTER);
        JPanel southPanel = new JPanel();
        southPanel.add(new JButton("Start"));
        this.add(southPanel, BorderLayout.SOUTH);
    }

    public static void main(String[] args) {
        PanelLayoutTest frame = new PanelLayoutTest();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);
    }

}

 

时间: 2024-10-02 17:43:55

LayoutDemo的相关文章

Android入门之TableLayout应用解析(二)_Android

本文在上一篇初步介绍TableLayout常用属性的基础上,将进一步介绍如何UI设计器设计TableLayout + TableRow.由于实际应用中,经常需要在代码里往TableLayout添加数据(9宫图也可以用TableLayout做出来 ),本文就是介绍这方面的简单使用方法. main.xml的代码如下,用到TableLayout的ID为TableLayout01: <?xml version="1.0" encoding="utf-8"?> &

Android入门之TableLayout应用解析(二)

本文在上一篇初步介绍TableLayout常用属性的基础上,将进一步介绍如何UI设计器设计TableLayout + TableRow.由于实际应用中,经常需要在代码里往TableLayout添加数据(9宫图也可以用TableLayout做出来 ),本文就是介绍这方面的简单使用方法. main.xml的代码如下,用到TableLayout的ID为TableLayout01: <?xml version="1.0" encoding="utf-8"?> &