1

Been looking around but couldn't find anything that explain how to do something like this:

Object rowData[] = { "Row1-Column1", "Row1-Column2", "Row1-Column3" };

Object columnNames[] = { "Column One", "Column Two", "Column Three" };

I already made a table with the editor, name: "jTable1".

1
  • I'm not sure how to use the arrays and the functions to populate the table. Eg: jTable1.addColumn(columnNames); gives an error. Commented Oct 29, 2012 at 14:45

2 Answers 2

5

Something like this will help you:

DefaultTableModel model = new DefaultTableModel(columnNames, 0);
model.addRow(rowData);
jTable1.setModel(model);
Sign up to request clarification or add additional context in comments.

Comments

4

You need a two-dimensional array for the row data. Try this:

Object rowData[][] = {{ "Row1-Column1", "Row1-Column2", "Row1-Column3" }};
Object columnNames[] = { "Column One", "Column Two", "Column Three" };
JTable table = new JTable(rowData, columnNames);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.