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

Java Swing编程

时间:2016-08-03 01:29:42      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:

最近在做一个Doc文件检测工具。

import java.awt.Color;
import java.awt.Dialog.ModalExclusionType;
import java.awt.Font;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;


public class Test01 extends JFrame {
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    public Test01() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setModalExclusionType(ModalExclusionType.TOOLKIT_EXCLUDE);
        setType(Type.UTILITY);
        setAlwaysOnTop(true);
        setBackground(Color.CYAN);
        setForeground(Color.CYAN);
        setTitle("\u6587\u4EF6\u68C0\u67E5\u5DE5\u5177");
        
        JLabel lblNewLabel = new JLabel("");
        
        textField = new JTextField();
        textField.setForeground(Color.WHITE);
        textField.setBackground(Color.WHITE);
        textField.setColumns(10);
        
        JButton btnNewButton = new JButton("打开");
        btnNewButton.setToolTipText("Only can select the path!");
        
        JLabel lblNewLabel_1 = new JLabel("New label");
        
        JLabel lblNewLabel_2 = new JLabel("New label");
        
        JLabel lblNewLabel_3 = new JLabel("New label");
        
        textField_1 = new JTextField();
        textField_1.setColumns(10);
        
        textField_2 = new JTextField();
        textField_2.setColumns(10);
        
        textField_3 = new JTextField();
        textField_3.setColumns(10);
        
        JLabel lblNewLabel_4 = new JLabel("文件选择路径");
        lblNewLabel_4.setFont(new Font("楷体", Font.BOLD, 12));
        GroupLayout groupLayout = new GroupLayout(getContentPane());
        groupLayout.setHorizontalGroup(
            groupLayout.createParallelGroup(Alignment.TRAILING)
                .addGroup(groupLayout.createSequentialGroup()
                    .addContainerGap(40, Short.MAX_VALUE)
                    .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                        .addGroup(groupLayout.createSequentialGroup()
                            .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
                                .addComponent(lblNewLabel_4)
                                .addComponent(lblNewLabel_2)
                                .addComponent(lblNewLabel_3)
                                .addComponent(lblNewLabel_1))
                            .addGap(28)
                            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                                .addComponent(textField, GroupLayout.PREFERRED_SIZE, 348, GroupLayout.PREFERRED_SIZE)
                                .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
                                    .addComponent(textField_3, Alignment.LEADING)
                                    .addComponent(textField_2, Alignment.LEADING)
                                    .addComponent(textField_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)))
                            .addGap(34)
                            .addComponent(btnNewButton)
                            .addContainerGap(55, Short.MAX_VALUE))
                        .addGroup(groupLayout.createSequentialGroup()
                            .addComponent(lblNewLabel)
                            .addGap(546))))
        );
        groupLayout.setVerticalGroup(
            groupLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(groupLayout.createSequentialGroup()
                    .addGap(26)
                    .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                        .addComponent(lblNewLabel)
                        .addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnNewButton)
                        .addComponent(lblNewLabel_4))
                    .addPreferredGap(ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                    .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
                        .addGroup(groupLayout.createSequentialGroup()
                            .addComponent(lblNewLabel_1)
                            .addGap(46))
                        .addGroup(groupLayout.createSequentialGroup()
                            .addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addGap(43)))
                    .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                        .addComponent(lblNewLabel_2)
                        .addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addGap(44)
                    .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                        .addComponent(lblNewLabel_3)
                        .addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(84, Short.MAX_VALUE))
        );
        getContentPane().setLayout(groupLayout);
    }
}
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.table.DefaultTableModel;


public class Test02 extends JFrame {
    private final JCheckBox checkBox = new JCheckBox("New check box");
    private final JCheckBox checkBox_1 = new JCheckBox("New check box");
    private final JCheckBox checkBox_2 = new JCheckBox("New check box");
    private final JCheckBox checkBox_3 = new JCheckBox("New check box");
    private final JLabel lblNewLabel = new JLabel("New label");
    private final JTable table = new JTable();
    public Test02() {
        setType(Type.UTILITY);
        setTitle("\u67E5\u8BE2\u7ED3\u679C");
        
        JScrollPane scrollPane = new JScrollPane();
        GroupLayout groupLayout = new GroupLayout(getContentPane());
        groupLayout.setHorizontalGroup(
            groupLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
                    .addGap(18)
                    .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
                        .addComponent(scrollPane, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 616, Short.MAX_VALUE)
                        .addGroup(groupLayout.createSequentialGroup()
                            .addComponent(lblNewLabel)
                            .addPreferredGap(ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                            .addComponent(checkBox)
                            .addGap(40)
                            .addComponent(checkBox_1)
                            .addGap(36)
                            .addComponent(checkBox_2)
                            .addGap(31)
                            .addComponent(checkBox_3)))
                    .addGap(17))
        );
        groupLayout.setVerticalGroup(
            groupLayout.createParallelGroup(Alignment.LEADING)
                .addGroup(groupLayout.createSequentialGroup()
                    .addGap(16)
                    .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                        .addGroup(groupLayout.createSequentialGroup()
                            .addGap(4)
                            .addComponent(lblNewLabel))
                        .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                            .addComponent(checkBox_3)
                            .addComponent(checkBox_2)
                            .addComponent(checkBox_1)
                            .addComponent(checkBox)))
                    .addGap(26)
                    .addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE)
                    .addContainerGap())
        );
        scrollPane.setViewportView(table);
        table.setModel(new DefaultTableModel(
            new Object[][] {
            },
            new String[] {
                "\u6587\u4EF6\u540D\u79F0"
            }
        ));
        getContentPane().setLayout(groupLayout);
    }
}

 

Java Swing编程

标签:

原文地址:http://www.cnblogs.com/xywhh/p/5731220.html

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