Main.java
01 /*
02  *
03  * All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved.
04  *
05  */
06 package demo.jtable;
07 
08 import java.awt.Font;
09 import javax.swing.JFrame;
10 import javax.swing.JScrollPane;
11 import javax.swing.JTable;
12 import javax.swing.table.DefaultTableModel;
13 
14 class Main extends JFrame {
15    private DefaultTableModel model;
16 
17    private Object[] tableHeader = { "Time", "Room A", "Room B", "Room C" };
18 
19    private static Object[][] tableData = { { " 9:00", "", "", "" },
20          { "10:00", "", "", "" }, { "11:00", "", "", "" },
21          { "12:00", "", "", "" }, { " 1:00", "", "", "" },
22          { " 2:00", "", "", "" }, { " 3:00", "", "", "" },
23          { " 4:00", "", "", "" }, { " 5:00", "", "", "" } };
24 
25    Main() {
26       super("Table Demo");
27 
28       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
29       setDefaultLookAndFeelDecorated(true);
30 
31       model = new DefaultTableModel(tableData, tableHeader);
32 
33       JTable table = new JTable(model);
34       table.setFont(new Font("Courier New", Font.PLAIN, 14));
35       getContentPane().add(new JScrollPane(table));
36       setSize(500, 200);
37       setVisible(true);
38    }
39 
40    public static void main(String[] args) {
41       javax.swing.SwingUtilities.invokeLater(new Runnable() {
42          public void run() {
43             new Main();
44          }
45       });
46    }
47 }