zoukankan      html  css  js  c++  java
  • java swing中对于JTable的使用(一)

    package com.robert.JTable;
    
    import javax.swing.*;
    import java.awt.*;
    
    /**
     * Created by IntelliJ IDEA.
     * User: Administrator
     * Date: 11-11-13
     * Time: 上午9:43
     * To change this template use File | Settings | File Templates.
     */
    public class PlanetTable {
    
        public static void main(String args[])
        {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new PlanetTableFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setVisible(true);
                }
            });
        }
    
    }
    

     
    package com.robert.JTable;
    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.print.PrinterException;
    
    /**
     * Created by IntelliJ IDEA.
     * User: Administrator
     * Date: 11-11-13
     * Time: 上午9:47
     * To change this template use File | Settings | File Templates.
     */
    public class PlanetTableFrame extends JFrame
    {
        private static int DEFAULT_WIDTH = 400;
        private static int DEFAULT_HEIGHT = 300;
        private Object[][] cells = {{"Mercury",2440.0,0,false, Color.yellow},
                {"Venus",6052.0,false,Color.yellow},{"Earth",6378.0,false,Color.blue},
                {"Saturn",60268.0,18,true,Color.orange},
                {"Uranus",25559.0,17,true,Color.blue},{"Nepture",24766.0,8,true,Color.blue},
                {"Pluto",1137.0,1,false,Color.black}
        };
    
        private String[] columnNames = {"Planet", "Radius", "Moons", "Gaseous", "Color"};
    
        public PlanetTableFrame()
        {
            setTitle("PlanetTable");
            setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
            final JTable table = new JTable(cells,columnNames);
            table.setAutoCreateRowSorter(true);
            add(new JScrollPane(table),BorderLayout.NORTH);
            JButton printButton = new JButton("print");
            printButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent event) {
                    try
                    {
                        table.print();
                    }
                    catch (PrinterException e)
                    {
                        e.printStackTrace();
                    }
                }
            });
    
            JPanel buttonPanel = new JPanel();
            buttonPanel.add(printButton);
            add(buttonPanel, BorderLayout.CENTER);
            buttonPanel.updateUI();
        }
    
    }
    

  • 相关阅读:
    数组优化 Dijkstra 最短路
    F
    树 (p155, 从中序和后续回复二叉树)
    矩阵连乘 LRJ白书 p141 栈 解析表达式
    Train Problem II HDU 1023 卡特兰数
    codevs 1166 矩阵取数游戏
    BZOJ 2754: [SCOI2012]喵星球上的点名
    2017.6.11 校内模拟赛
    HDU 2896 病毒侵袭
    UvaLive 4670 Dominating Patterns
  • 原文地址:https://www.cnblogs.com/mengjianzhou/p/5986892.html
Copyright © 2011-2022 走看看