简体   繁体   English

在JTable中禁用水平自动滚动

[英]Disable horizontal autoscroll in JTable

I have a JTable that is filled dynamically. 我有一个动态填充的JTable。 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. 提前致谢。

Call: 呼叫:

jscrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

which will make sure no horizontal JScrollBar is created for the JScrollPane . 这将确保没有为JScrollPane创建水平JScrollBar

Perhaps also need to ensure the JScrollPane fits the JTable horizontally via: 也许还需要通过以下方法确保JScrollPane水平适合JTable

table.setPreferredScrollableViewportSize(table.getPreferredSize());
JScrollPane jscrollpane = new JScrollPane(table);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM