3

I have a JTable and I'm using the DefaultTableModel. I have one row, but I'm trying to add many columns using a for loop because the table is created dynamically.

With addColumn, I understand the first argument should be a string for the column name, but how can I pass a double for the data value in the table? I have read the definitions (the use of object or vector) but I'm having no luck with them:

String colName = "ColName";
double value = 1.2;
model.addColumn(colName, new double[]{ value });

1 Answer 1

3

addColumn(Object columnName, Object[] columnData) this method only accepting arrays of objects which are extending from java.lang.Object. So if you use new Double[]{ value } instead of new double[]{ value } it will work.

Sign up to request clarification or add additional context in comments.

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.