出于某種原因,我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
提交
取消