Friday, April 15, 2005

howto:horizontal_table_scroll [SwingWiki]

howto:horizontal_table_scroll [SwingWiki]: "By default, JTable scrolls only vertically, not horizontally (and cell width is automatically adjusted to fit into the available space, even in JScrollPane). If the table contains a lot of columns (10 ), the columns will become too short for any use, so you will have to enable horizontal scrolling.

To enable horizontal scrolling,

The downside to this method is that you have to set cell width manually. You might try to put the table into a JPanel of fixed size, without all this tweaking, and then put the enclosing JPanel into a JScrollPane. However, this leaves you with the problem of Missing JTable Header.

First, call table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF) to turn off automatic resizing. Then, manually set cell width for each column. In earlier JDK versions (1.3), you will also have to activate the horizontal scrollbar by hand - create JScrollPane with the following constructor call JSCrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS)
"

No comments: