开发者

Common scroll bar for two JTable

I have two tables. One table is a fixed column(ie. the table will not have any impact on the scrolling of scrollbar of another table). These two tables have to be commonly scrolled by a vertical scrollbar.开发者_JS百科Any idea or suggesstion or examples?

This is a continuation of the previous question. Fixed Column The answer for which is here FixedColumn.java


Fixed Column Table or Row Number Table give some ideas.


There is a simple solution to this problem. Just put your "fixed column" table into "row header" decoration area of scroll pane used for the second table. it should something like following:

JTable table1 = new JTable();
JTable table2 = new JTable();
JScrollPane scrollPane = JScrollPane(table2);

JViewport viewport = new JViewport();
viewport.setView(table1);
viewport.setPreferredSize(table1.getPreferredSize());
scrollPane.setRowHeaderView(viewport);
scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER,table1.getTableHeader());    

You can find more information at http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html#decorations

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜