Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JFrame;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.SwingUtilities;
- public class TableExample extends JFrame
- {
- public TableExample()
- {
- //headers for the table
- String[] columns = new String[] {
- "Id", "Name", "Hourly Rate", "Part Time"
- };
- //actual data for the table in a 2d array
- Object[][] data = new Object[][] {
- {1, "John", 40.0, false },
- {2, "Rambo", 70.0, false },
- {3, "Zorro", 60.0, true },
- };
- //create table with data
- JTable table = new JTable(data, columns);
- //add the table to the frame
- this.add(new JScrollPane(table));
- this.setTitle("Table Example");
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.pack();
- this.setVisible(true);
- }
- public static void main(String[] args)
- {
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- new TableExample();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement