tags:

views:

438

answers:

1

Is there any way to enable horizontal scrollbar whenever necessary??

The situation was as such:

I've a JTable on Netbeans, one of the cells, stored a long length of data. Hence, I need to have horizontal scrollbar. Anyone has idea on this?

THanks in advance for any helps..

+3  A: 

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);
romaintaz
exactly........
ammoQ
In Netbeans, the JScrollPane with JTable intial components have been set up in a method which is cannot be modified.Any idea to solve this? I tried putting in the method, however, the table disappeared once I put above code in a button handler for testing purpose.
Mr CooL
@MrCooL could you edit your original post to show your Java code?
romaintaz
okay, it works finally with some manipulations in Netbeans...Thanks romaintaz! ;)
Mr CooL
@MrCooL You're welcome :)
romaintaz