我目前有一个SwingWorker,它发送HTTP请求,我重写了SwingWorker的done()方法来更改JFrame中的内容。根据从服务器返回的值,我想基本上删除所有内容并在JFrame上添加新的成员面板。
现在,我面临的问题是,当我在JFrame上调用以下方法时,它不会从JFrame中删除任何内容,也不会更改其包含在框架内的内容。
现在,我面临的问题是,当我在JFrame上调用以下方法时,它不会从JFrame中删除任何内容,也不会更改其包含在框架内的内容。
//TODO: Investigate why JFrame content pane won't repaint.
f.removeAll();
//Pass the frame f reference only into MainDisplay, it doesn't actually do anything apart from allowing a class to add a JMenuBar on the JFrame.
f.add(new MainDisplay(f));
f.getContentPane().invalidate();
f.getContentPane().validate();
f.getContentPane().repaint();
我目前的解决方案如下,但我宁愿更改JFrame的内容而不是加载一个新的JFrame。
f.dispose();
f=new ApplicationFrame();
我已经查看了之前在这里和Google上的答案,有些人建议使用validate()或invalidate()来调用repaint()以重绘JFrame。
任何建议/帮助将不胜感激。
编辑:我认为我需要更多地调试,因为肯定还有其他问题。