Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Columns with Data in jTable

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 });
like image 365
Jonathan Farmer Avatar asked Mar 26 '26 13:03

Jonathan Farmer


1 Answers

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.

like image 189
rdonuk Avatar answered Mar 28 '26 03:03

rdonuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!