Since I will be taking the user's input as to how many rows he/she wants, I want to specify the number of rows in constructing a table. I can't initialize the data in a two-dimensional array because the number of cells can be changed according to the input of the user. So how do I specify the rows using just an integer.
1 Answer
I can't initialize the data in a two-dimensional array because the number of cells can be changed according to the input of the user.
Why not declare the array as a non-static field in the class, but simply initialize it only after getting user input?
Myself I'd extend DefaultTableModel and use the constructor that allows a row count as one of the parameters:
public DefaultTableModel(Object[] columnNames,
int rowCount)
1 Comment
Paecko
Thanks for telling me about DefaultTableModel. Didn't know about it since I am new to Java and programming in general.