First, add your JTable
inside a JScrollPane
and set the policy for the existence of scrollbars:
new JScrollPane(myTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
Then, indicate that your JTable must not auto-resize the columns by setting the AUTO_RESIZE_OFF
mode:
myJTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…