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(); } }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值