我在顯示JFrame上的組件時遇到問題。我正在關閉當前窗口並打開新窗口並希望顯示jLabel,但沒有任何事情發生。代碼如下:JFrame不顯示組件
Frame[] nF = DBChooser.getFrames();
nF[0].setVisible(false);
JFrame windoow = new JFrame("Processing");
JPanel pan = new JPanel();
windoow.setPreferredSize(new Dimension(400, 150));
pan.setPreferredSize(new Dimension(400, 150));
JLabel textLabel = new JLabel ("Processing...");
textLabel.setLayout(null);
pan.setLayout(null);
windoow.setLayout(null);
pan.add(textLabel);
pan.revalidate();
pan.repaint();
windoow.getContentPane().add(pan);
windoow.setLocationRelativeTo(null);
windoow.pack();
windoow.setVisible(true);
我感謝所有幫助
1)Java的圖形用戶界面有不同的OS」,屏幕大小,屏幕分辨率等方面的工作在不同的地區使用不同的PLAFs。因此,它們不利於像素的完美佈局。請使用佈局管理器或[它們的組合](http://stackoverflow.com/a/5630271/418556)以及[white space]的佈局填充和邊框(http://stackoverflow.com/a/17874718/ 418556)。 2)爲了更快地獲得更好的幫助,請發佈[MCVE]或[簡短,獨立,正確的示例](http://www.sscce.org/)。 3)以最小尺寸提供ASCII圖形或簡單的GUI圖形佈局* –
..如果可調整大小,則具有更大的寬度和高度。 –