Frage

Is there a function in Java library that would limit JTable size only to a number of rows that you set? I cant seem to find anything that would help me with it.

My program allows you to add and remove items from the JTable. JTable counts the number of rows in use and returns the number Is there a way to limit number of rows only to 100.

War es hilfreich?

Lösung

ou can use setRowCount(int rowCount) on you table dataModel.

which will sets the number of rows in the model. If the new size is greater than the current size, new rows are added to the end of the model If the new size is less than the current size, all rows at index rowCount and greater are discarded.

For Example:

DefaultTableModel dtm = (DefaultTableModel) tabel1.getModel();
dtm.setRowCount(100); // though I would use some variable here
tabel1.setModel(dtm);

Please find the explanation here.

Andere Tipps

I'm looking to set a limit to amount of cars can be added.

Then override the addRow(...) method of the DefaultTableModel to not allow you to add more than 100 rows of data.

There is nothing in the API that limits the number of rows since the API is meant to be dynamic.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top