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?
To create a scrollable JTable component we have to use a JScrollPane as the container of the JTable . Besides, that we also need to set the table auto resize mode to JTable. AUTO_RESIZE_OFF so that a horizontal scroll bar displayed by the scroll pane when needed.
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);
Set the AutoResizeMode
to OFF
in the properties of the jTable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With