Trying to get a JTable + JScrollPane to scroll

。_饼干妹妹 提交于 2019-12-06 12:18:30

This is moving the table into the scroll panes column header position, which doesn't have scroll bars...get rid of it...

tableTestScrollPane_1.setColumnHeaderView(tableTest_1);

This is essentially removing the tableTest_2 from the scroll pane and placing it within a new view port and adding it to the row header...which has no scroll bars.

viewport.setView(tableTest_2);
...
tableTestScrollPane_2.setRowHeaderView(viewport);

A component can only belong to a single parent...

Try something like instead;

tableTest_1 = new JTable(tableTestModel_1);
tableTest_1.setBounds(new Rectangle(10, 10, 395, 100));
tableTest_1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tableTestScrollPane_1 = new JScrollPane(tableTest_1);

tableTest_2 = new JTable(tableTestModel_2);
tableTest_2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
tableTest_2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tableTestScrollPane_2 = new JScrollPane(tableTest_2);

getContentPane().add(tableTestScrollPane_1);
getContentPane().add(tableTestScrollPane_2);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!