Question

I have a JTable that is filled dynamically. It has only two columns, the first is a boolean value and the second is a string.

The problem is that when I select a row in the string column, the table autoscrolls to the right hiding the first column.

How do I change this behaviour?

If I disable autoscroll, the user is not able to scroll to the bottom through the arrow keys.

Any ideas?

Thanks in advance.

Était-ce utile?

La solution

Call:

jscrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

which will make sure no horizontal JScrollBar is created for the JScrollPane.

Perhaps also need to ensure the JScrollPane fits the JTable horizontally via:

table.setPreferredScrollableViewportSize(table.getPreferredSize());
JScrollPane jscrollpane = new JScrollPane(table);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top