How to create a dynamic Jtable?

Asked

Viewed 538 times

1

I have a JTable in my form, I wanted the size(number of rows and columns) of the table to be according to the number the user enters, how to do in java?

  • What you’ve tried to do?

  • Still nothing, I found no hint!

  • Ai complicates, the answer would be too broad, it would be good for you to post some attempt, or what you have done so far, to have a basis of response.

  • Only the command to set the number of rows and columns of a jtable would already serve

  • The answer below helped you? You can accept it by clicking on v next to the post :)

1 answer

2

It is possible to create an empty table, as one of the constructors of JTable allows passing the number of rows and columns, and the table is internally created using the DefaultTableModel.

int numLinhas = 5;
int numColunas = 3;
JTable table = new JTable(numLinhas, numColunas);

The above example displays something like this:

inserir a descrição da imagem aqui

Just remember to pass the JTable for a JScrollPane, otherwise the table header will not be displayed and possibly not the Scrolls when needed.


References:

How to Use Tables(Oracle)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.