Ciao grazie per la risposta, ho fatto le modifiche che mi hai detto ma niente..
codice:
public class nameTable extends JFrame{
public void nameTable(){
java.awt.Container c = getContentPane();
c.setLayout(new GridLayout(5,2));
final String[] columnNames = {"UserName",
"Time",};
final Object[][] data = {
{"+name+", new Integer(5), new Boolean(false)},
{"+name+", new Integer(3), new Boolean(true)},
{"+name+", new Integer(2), new Boolean(false)},
{"+name+", new Integer(20), new Boolean(true)},
{"+name+", new Integer(10), new Boolean(false)}
};
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 100));
table.setFillsViewportHeight(true);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.add(table);
c.add(scrollPane, BorderLayout.CENTER);
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
}
System.out.println();
}
System.out.println("--------------------------");
table.setVisible(true);
nameTable contentPane = new nameTable();
c.add(contentPane, BorderLayout.SOUTH);
c.setBackground(Color.yellow);
c.setForeground(Color.blue);
c.setSize(width,height);
c.setVisible( true );
}
}
Non so proprio perchè..