📄 shiptable.java
字号:
//file: ShipTable.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.*;public class ShipTable { public static class ShipTableModel extends AbstractTableModel { private String[] headings = new String[] { "Number", "Hot?", "Origin", "Destination", "Ship Date", "Weight" }; private Object[][] data = new Object[][] { { "100420", Boolean.FALSE, "Des Moines IA", "Spokane WA", "02/06/2000", new Float(450) }, { "202174", Boolean.TRUE, "Basking Ridge NJ", "Princeton NJ", "05/20/2000", new Float(1250) }, { "450877", Boolean.TRUE, "St. Paul MN", "Austin TX", "03/20/2000", new Float(1745) }, { "101891", Boolean.FALSE, "Boston MA", "Albany NY", "04/04/2000", new Float(88) } }; public int getRowCount( ) { return data.length; } public int getColumnCount( ) { return data[0].length; } public Object getValueAt(int row, int column) { return data[row][column]; } public String getColumnName(int column) { return headings[column]; } public Class getColumnClass(int column) { return data[0][column].getClass( ); } } public static void main(String[] args) { // create a JFrame to hold the table JFrame f = new JFrame("ShipTable v1.0"); f.addWindowListener(new WindowAdapter( ) { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.setSize(500, 200); f.setLocation(200, 200); // create the data model and the JTable TableModel model = new ShipTableModel( ); JTable table = new JTable(model); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // put it all together f.getContentPane( ).add(new JScrollPane(table)); f.setVisible(true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -