Changing and Updating JPanel Components externally, from JFrame is not Working, Swing

杀马特。学长 韩版系。学妹 提交于 2019-11-29 17:13:20
MyPanel myPanel = addNewTab();
myPanel.callFilling(); //OUTER CALL!
myPanel.revalidate();
myPanel.repaint();
addNewTab();

Not sure what you are trying to do.

You create a MyPanel object and invoke callFilling() on it to set the values in the TableModel. But you never actually add the panel to the frame.

You only need to invoke revalidate() and repaint() when you add components to a visible panel.

Then you invoke addNewTab() which does:

MyPanel myPanel = new MyPanel();
myTabbed.insertTab(title, null, new MyPanel(), null, idx);
return myPanel;

Again, this doesn't make any sense you create 2 MyPanel objects. You add one object to a tabbed pane, but then you return the second MyPanel object.

So you have created 3 MyPanel objects.

I really am not sure what you are trying to do. I don't know if you are trying to add a panel to the frame, or a panel to the tabbed pane, so I can't really make a specific suggestion.

In any case you need to structure you code so that only on MyObject object is created and you need to add that panel to either the tabbed pane or the frame, but not both.

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