简体   繁体   English

用另一个jpanel替换一个jpanel

[英]replacing one jpanel with another jpanel

I want to replace the current panel and call another panel in JPanel forms. 我想替换当前面板并在JPanel表单中调用另一个面板。 I try to do using setContentPane() and getContentPane() method but it gives error. 我尝试使用setContentPane()getContentPane()方法来执行操作,但它给出了错误。 how can I do that.... I also try this but clear all the componens but do not add anything 我该怎么做...。我也尝试了一下,但清除了所有组件,但不添加任何内容

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" “我想替换当前面板并以JPanel形式调用另一个面板”

Instead of trying to add an remove panels, use a CardLayout . 与其尝试添加移除面板, CardLayout使用CardLayout Seeing how you're using Netbeans GUI Builder, see How to Use CardLayout with Netbeans GUI Builder . 要查看您如何使用Netbeans GUI Builder,请参阅如何将CardLayout与Netbeans GUI Builder一起使用 What the CardLayout does is allow you to change between different views without having to add and drop panels, which can be troublesome. CardLayout作用是允许您在不同的视图之间进行更改,而无需添加和放置面板,这可能很麻烦。

Also you may want to debug your if statement. 另外,您可能想调试if语句。 Hard to tell with only the little but of code you're showing. 仅显示少量代码就很难说清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM