0

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
  • Can you add the code you have written so far? Commented Dec 16, 2014 at 0:29

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for telling me about DefaultTableModel. Didn't know about it since I am new to Java and programming in general.

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.