//file: DullShipTable.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class DullShipTable {
public static void main(String[] args) {
// create some tabular data
String[] headings =
new String[] {"Number", "Hot?", "Origin",
"Destination", "Ship Date", "Weight" };
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) }
};
// create a JFrame to hold the table
JFrame f = new JFrame("DullShipTable 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
JTable table = new JTable(data, headings);
// put it all together
f.getContentPane( ).add(new JScrollPane(table));
f.setVisible(true);
}
}
|