我想替换当前面板并以 JPanel
形式调用另一个面板。
我尝试使用 setContentPane()
和 getContentPane()
方法,但它给出了错误。
我怎样才能做到这一点....
我也尝试过这个,但清除所有组件但不添加任何内容
private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
if (new ConnectionFactory().userLoginCheck(usernameText.getText(), new String(passwordText.getPassword()))) {
removeAll();
add(new ChangeUsernamePassword());
revalidate();
repaint();
//new Welcomeboard();
} else {
warningLabel.setText("Invalid Username Or Password!!!");
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(DashboardPanel.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(DashboardPanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
最佳答案
"I want to replace the current panel and call another panel in JPanel forms"
不要尝试添加删除面板,而是使用 CardLayout
。要了解如何使用 Netbeans GUI Builder,请参阅 How to Use CardLayout with Netbeans GUI Builder 。 CardLayout
的作用是允许您在不同的 View 之间进行更改,而无需添加和删除面板,这可能会很麻烦。
您可能还想调试您的 if 语句。仅凭您所显示的代码很难判断。
关于java - 将一个 jpanel 替换为另一个 jpanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22735049/