简体   繁体   中英

replacing one jpanel with another jpanel

I want to replace the current panel and call another panel in JPanel forms. I try to do using setContentPane() and getContentPane() method but it gives error. 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"

Instead of trying to add an remove panels, use a CardLayout . Seeing how you're using Netbeans GUI Builder, see How to Use CardLayout with 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.

Also you may want to debug your if statement. Hard to tell with only the little but of code you're showing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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