Advertisement
artcstr

exemplo tabela

May 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import javax.swing.JScrollPane;
  3. import javax.swing.JTable;
  4. import javax.swing.SwingUtilities;
  5. public class TableExample extends JFrame
  6. {
  7. public TableExample()
  8. {
  9. //headers for the table
  10. String[] columns = new String[] {
  11. "Id", "Name", "Hourly Rate", "Part Time"
  12. };
  13.  
  14. //actual data for the table in a 2d array
  15. Object[][] data = new Object[][] {
  16. {1, "John", 40.0, false },
  17. {2, "Rambo", 70.0, false },
  18. {3, "Zorro", 60.0, true },
  19. };
  20. //create table with data
  21. JTable table = new JTable(data, columns);
  22.  
  23. //add the table to the frame
  24. this.add(new JScrollPane(table));
  25.  
  26. this.setTitle("Table Example");
  27. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28. this.pack();
  29. this.setVisible(true);
  30. }
  31.  
  32. public static void main(String[] args)
  33. {
  34. SwingUtilities.invokeLater(new Runnable() {
  35. @Override
  36. public void run() {
  37. new TableExample();
  38. }
  39. });
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement