這很奇怪,我不知道爲什麼,但我不能從我的框架中刪除我的jpanel。 我什麼都試過,但沒有這個instrunctions後,我還是繼續看的JPanel:java swing - 從框架中刪除jpanel
frame.getContentPane()刪除(myPanel)。
我也試圖做的事:
frame.remove(...);
frame.add(...);
frame.revalidate();
frame.repaint();
但我仍然繼續看到在幀面板。 這是我的代碼(IM制定關於學生注意到一個小應用程序),現在我想刪除我的第一板只是做了一個實驗:
package StudApp;
import java.awt.BorderLayout;
public class StudApp {
private JPanel homeFirstRun;
private ArrayList<Corso> corsi = new ArrayList<Corso>();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new StudApp();
}
});
}
/**
* Create the frame.
*/
public StudApp() {
JFrame frame = new JFrame("Student Note");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(100, 100, 450, 300);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu menuHelp = new JMenu("Help");
menuBar.add(menuHelp);
JMenuItem menuIstrStud = new JMenuItem("Istruzioni Student Note");
menuHelp.add(menuIstrStud);
homeFirstRun = new JPanel();
homeFirstRun.setBorder(new EmptyBorder(5, 5, 5, 5));
frame.setContentPane(homeFirstRun);
homeFirstRun.setLayout(null);
JLabel welcomeMessage = new JLabel("Welcome to Student Note");
welcomeMessage.setBounds(5, 5, 424, 18);
welcomeMessage.setForeground(Color.DARK_GRAY);
welcomeMessage.setHorizontalAlignment(SwingConstants.CENTER);
welcomeMessage.setFont(new Font("Verdana", Font.BOLD, 14));
homeFirstRun.add(welcomeMessage);
JLabel welcomeCit = new JLabel("\"Software is like sex, it's better when it's free.\"");
welcomeCit.setFont(new Font("Verdana", Font.ITALIC, 11));
welcomeCit.setHorizontalAlignment(SwingConstants.CENTER);
welcomeCit.setBounds(35, 199, 361, 14);
homeFirstRun.add(welcomeCit);
JTextArea welcomeTextArea = new JTextArea();
welcomeTextArea.setFont(new Font("Verdana", Font.PLAIN, 13));
welcomeTextArea.setText(" I think it's your first time here.\n\n"
+ " So the first step is to create a new course to\n insert your grades.\n\n");
welcomeTextArea.setEditable(false);
welcomeTextArea.setBounds(27, 34, 381, 184);
homeFirstRun.add(welcomeTextArea);
frame.setVisible(true);
frame.remove(homeFirstRun); //here im doing a test because i wanna see if the homeFirstRun panel go out from the frame
// but not it remains.
}
}
你可以試試'myPanel.setVisible(假)' – ferrerverck
我不需要因爲這個面板必須在框架上只是第一次(當你第一次打開程序時)如果你第二次打開程序,你會看到另一件事......所以我認爲隱藏面板不是一個好主意,我想永遠刪除它。 –