-
Fill jtable columns
Hi all.
Iam trieing to make a JTable. That get filld by 2 ArrayLists.
The problem is that i want that array list 1 fills column 1 like this.
1.
2.
3.
4.
5.
etc.
And the other arraylist fills the column beside it.
My jtable looks like this now!
Code:
String[] setColumnIdentifiers = {leg.getNameP1(), leg.getNameP2()};
model = new DefaultTableModel(setColumnIdentifiers, 0);
scoreTable = new JTable(model);
scoreTable.getTableHeader().setFont( new Font( "Dialog" , Font.BOLD, 13 ));
scoreTable.getTableHeader().setReorderingAllowed(false);
scoreTable.setForeground(Color.WHITE);
scoreTable.setBackground(Color.BLACK);
scoreTable.setFont(new Font("Tahoma", 1, 18));
scoreTable.setEnabled(false);
scoreTable.setFocusable(false);
scoreTable.setShowHorizontalLines(false);
scoreTable.setShowVerticalLines(false);
scrollPane = new JScrollPane(scoreTable);
scrollPane.getViewport().setBackground(Color.BLACK);
scrollPane.setBounds(0, 0, 500, 500);
right.add(scrollPane);
-
Re: Fill jtable columns
Can't you just call JTable.setValueAt()?
-
Re: Fill jtable columns
The DefaultTableModel only supports a 2-dimensional array or a Vector of Vectors. So you need to copy your data to either one of those objects first.
Or the other approach is to create a custom table model that uses an ArrayList as is demonstrated in List Table Model « Java Tips Weblog.