我想水平滚动条添加到我的JScrollPane的,因为我的表,现在看起来像下面这样:如何水平/垂直滚动条添加到JScrollPane中
这里是我的代码来创建表:
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到:
this.scrollPane = new JScrollPane(this.table,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
滚动条是有的,但我还是不能水平滚动。请参阅下面的截图。
谢谢!
+1的自动调整模式。默认设置是强制这些列适合所提供的空间。 – camickr 2012-02-06 18:20:55