带有水平滚动条的 JTable [英] JTable with horizontal scrollbar

查看:46
本文介绍了带有水平滚动条的 JTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在需要时启用水平滚动条吗?

Is there any way to enable horizontal scroll-bar whenever necessary?

情况是这样的:我有一个 JTable,其中一个单元格存储了很长的数据.因此,我需要有水平滚动条.

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.

有人对此有想法吗?

推荐答案

首先,在 JScrollPane 中添加您的 JTable 并设置滚动条存在的策略:

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);

然后,通过设置 AUTO_RESIZE_OFF 模式指示您的 JTable 不得自动调整列的大小:

Then, indicate that your JTable must not auto-resize the columns by setting the AUTO_RESIZE_OFF mode:

myJTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

这篇关于带有水平滚动条的 JTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆