Search code examples
javaswingjtablejscrollpanejscrollbar

How can a scrollpane of jtable show whole data vertically without scrolling


I have a Jtable and it enclose in a default scrollpane. When my table grow up with its row, a vertical scrollpane appear. But i don't want it. How can i show whole row vertically without vertical scrollbar.

enter image description here


Solution

  • After loading the data into the TableModel you can set the preferred size of the viewport:

    JTable table = new JTable(model);
    table.setPreferredScrollableViewportSize(table.getPreferredSize());
    JScrollPane scrollPane = new JScrollPane( table );