出于某种原因,我JLabel没有显示,我不知道为什么(editString确实有一个值)。compFrame.removeAll();JPanel editPane = new JPanel();editPane.setLayout(new GridLayout(0,1));compFrame.add(editPane);//JLabel lastValue = new JLabel(editString);editPane.add(new JLabel(editString));compFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);compFrame.setVisible(true);
1 回答
狐的传说
TA贡献1804条经验 获得超3个赞
您应该在 ContentPane 上使用 removeAll。试试这个
compFrame.getContentPane().removeAll();
removeAll 的 API 文档说:
此方法更改与布局相关的信息,因此使组件层次结构无效。如果容器已被显示,则此后必须验证层次结构以反映更改。
添加回答
举报
0/150
提交
取消