I kept on searching and nothing shows a good answer, I'm a bit new to the in depth parts of Java, so just asking.. How to resize or dynamically resize the JTable
depending on its rows, instead of having a vertical scrollbar?
My method (not working):
After I add data into the table I then resize the table by its parent JScrollPane
, since table resize automatically with its rows, but scroll pane doesn't but rather just stays the same before data was added. I've already tried these methods:
itemTable.setPreferredScrollableViewportSize(...);
jScrollPane.setPreferredSize(...);//using the itemTable width and height
jScrollPane.setSize(...);//using the itemTable width and height
Still nothing works, can someone help me? Or maybe other solutions?