fubarable

IndexOutOfBoundsException test

Oct 19th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import javax.swing.*;
  2. import javax.swing.table.*;
  3.  
  4. public class Foo {
  5.     public static void main(String[] args) {
  6.         SwingUtilities.invokeLater(new Runnable() {
  7.             public void run() {
  8.                 Object columnNamesPax[] = { "#", "Name", "Surname", "Sex",
  9.                         "Age", "Class" };
  10.                 Object[][] data = new Object[5][columnNamesPax.length];
  11.  
  12.                 JTable tablePax = new JTable(new DefaultTableModel(data,
  13.                         columnNamesPax));
  14.  
  15.                 DefaultTableModel defaultModel = (DefaultTableModel) tablePax
  16.                         .getModel();
  17.                 System.out.println(tablePax.getColumnCount());
  18.                 defaultModel.addRow(new Object[] { "1", "2", "3", "4", "5", "6" });
  19.                
  20.                 JOptionPane.showMessageDialog(null, new JScrollPane(tablePax));
  21.             }
  22.         });
  23.     }
  24. }
Add Comment
Please, Sign In to add comment