JTable 未显示
在我的应用程序中,一切都是分布式的。
- 在执行操作时,应用程序从数据库检索数据并将其保存在 ArrayList
中。 我创建了一个
RelativeTableModel
对象,并在其中传递ArrayList
。公共无效RelationsClicked() { ArrayList<关系>数据 = myParent.dbOperation.getRelations(); 相对表模型 tModel = 新的相对表模型(数据); // AbstractTableModel 的子类 myParent.SetBrowsePanelData(tModel); myParent.SetMainPanel(CashAccountingView.BROWSEPANEL); }
- 我有一个
BrowseListPanel
类,该类在JScrollPane
中有一个JTable
。它的实例已在主应用程序中创建。 - 我将模型传递给
BrowseListPanel
并最终显示面板。
- 我有一个
Code:
public void SetBrowsePanelData(AbstractTableModel tModel) {
browsePanel.setTModel(tModel);
}
// BrowseListPanel's Code
public void setTModel(AbstractTableModel tModel) {
this.tModel = tModel; // tModel = AbstractTableModel
}
// Show the Panel
public void SetMainPanel(String panel) {
activePanel = panel;
SetFontSize();
cards.show(mainPanel, panel);
mainPanel.revalidate();
mainPanel.repaint();
}
但我没有看到表格
。我相信 BrowseListPanel
的对象(包含 JTable
)已经创建并且可以创建。随后添加TableModel
。因此,应该在 setTModel()
中触发某种事件。
我说得对吗?如果是这样,应该抛出什么事件以及它的实现应该是什么。
In my application everything is distributed.
- On a action, application retrieves data from DB and saves in
ArrayList<T>
. I create an object of
RelativeTableModel
where I pass theArrayList<T>
.public void RelationsClicked() { ArrayList<Relation> data = myParent.dbOperation.getRelations(); RelativeTableModel tModel = new RelativeTableModel(data); // subclass of AbstractTableModel myParent.SetBrowsePanelData(tModel); myParent.SetMainPanel(CashAccountingView.BROWSEPANEL); }
- I have a
BrowseListPanel
class that has aJTable
inJScrollPane
. Its instance is already created in the main application. - I pass the model to
BrowseListPanel
and finally show the panel.
- I have a
Code:
public void SetBrowsePanelData(AbstractTableModel tModel) {
browsePanel.setTModel(tModel);
}
// BrowseListPanel's Code
public void setTModel(AbstractTableModel tModel) {
this.tModel = tModel; // tModel = AbstractTableModel
}
// Show the Panel
public void SetMainPanel(String panel) {
activePanel = panel;
SetFontSize();
cards.show(mainPanel, panel);
mainPanel.revalidate();
mainPanel.repaint();
}
But I don't see the Table
. I believe as the object of BrowseListPanel
(containing the JTable
) is already created & later the TableModel
is added. So some sort of event should be fired in setTModel()
.
Am I right? If so, what event should be thrown and what should be its implementation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用 表格上的
setModel()
应该足够了,但您可以在模型上显式调用fireTableStructureChanged()
作为帮助解决问题的方法。另外,请验证您是否正在处理事件调度线程。
附录:这是一个展示基本方法的 sscce。
Invoking
setModel()
on the table should be sufficient, but you might callfireTableStructureChanged()
on the model explicitly as a way to help sort things out.Also, verify that you are working on the event dispatch thread.
Addendum: Here's an sscce that shows the basic approach.