Dynamically adding JTable to JScrollPane

非 Y 不嫁゛ 提交于 2019-12-05 09:45:16

You should add component not to JScrollPane but to its JViewport:

scrollPane.getViewport ().add (table);

Instead of adding table to the JScrollPane Create a viewport of scrollpane and then sets its view as table. using following code instead:
scrollPane.setViewportView(table)

Generally, you create the JTable and the JScrollPane together, even though you have no values yet.

It's better to use a DefaultTableModel, or a TableModel that you extend, for a dynamic table.

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