Is there any way to enable horizontal scroll-bar whenever necessary?
The situation was as such: I've a JTable
, one of the cells, stored a long length of data. Hence, I need to have horizontal scroll-bar.
Anyone has idea on this?
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);