如何将水平/垂直滚动条添加到JScrollPane [英] How to add horizontal/vertical scrollbars to JScrollPane
本文介绍了如何将水平/垂直滚动条添加到JScrollPane的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的JScrollPane中添加水平滚动条,因为我的表现在看起来如下所示:
I want to add horizontal scrollbars to my JScrollPane, because my table right now looks like the one below:
这是我创建表格的代码:
Here is my code to create the table:
this.table = new JTable();
this.table.setShowGrid(false);
this.table.getTableHeader().setFont(ReportViewConstants.TABLE_FONT);
this.table.setFont(ReportViewConstants.TABLE_FONT);
this.scrollPane = new JScrollPane(this.table);
Dimension size = new Dimension(300, 400);
this.scrollPane.setPreferredSize(size);
this.scrollPane.setMinimumSize(size);
this.scrollPane.getViewport().setBackground(Color.WHITE);
你能指出我做错了什么吗?当我更改行以创建JScrollPane时:
Can you point out what I'm doing wrong? When I changed the line to create a JScrollPane to:
this.scrollPane = new JScrollPane(this.table,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
滚动条在那里,但我仍然无法水平滚动。请参阅下面的屏幕截图。
The scrollbars are there, but I still cannot scroll horizontally. See the screenshot below.
谢谢!
推荐答案
你必须为 JTable#setAutoResizeMode ,更多内容在<$ c中描述$ c> JTable的教程设置和更改列宽
You have to set for JTable#setAutoResizeMode, more is described in JTable's
tutorial Setting and Changing Column Widths
这篇关于如何将水平/垂直滚动条添加到JScrollPane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文