0

I'm making a GUI with Netbeans in JAVA. My idea is something like this:

JFrame -> contains a JPanel -> call a JDialog.

                            -> call a second JDialog

The idea is that I want to read something in the first JDialog, and when the user finish with this JDialog, he push a Button. This JDialog dispose() and the JPanel calls another JDialog.

My idea is something like a Project Wizard in Netbeans or something like this.

The problem is: GroupLayout can only be used with one Container at a time.

This is my code:

public class SubjectsPanel extends javax.swing.JPanel {
        private AddSubject addsubject; //Is an own class that inherites from JDialog.
        private AddGroups addgroups; //Is another own class that inherites from JDialog.
        private JFrame jf;




    public SubjectsPanel(JFrame fr) {
        jf = fr;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

    }

    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
        addsubject = new AddSubject(jf,true);
        addsubject.setSize(700, 350);
        addsubject.setLocationRelativeTo(this);
        addsubject.setTitle("Adding New Subject Wizard");
        addsubject.setVisible(true);
        addsubject.addWindowListener(new WindowListener() {

            @Override
            public void windowOpened(WindowEvent we) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void windowClosing(WindowEvent we) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void windowClosed(WindowEvent we) {
                if(addsubject.getBool()){                    
                    addgroup = new AddGroup(jf,true);
                    addgroup.setSize(700, 350);
                    addgroup.setLocationRelativeTo(this);
                    addgroup.setTitle("Adding New Group Wizard");
                    addgroup.setVisible(true);
                }
            }

            @Override
            public void windowIconified(WindowEvent we) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void windowDeiconified(WindowEvent we) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void windowActivated(WindowEvent we) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }

            @Override
            public void windowDeactivated(WindowEvent we) {
            }
        });
    }                                                
}

Of course I omitted some parts of code that I think that it's irrelevant. The problem is in the WindowListener, exactly here:

addgroup = new AddGroup(jf,true);
addgroup.setSize(700, 350);
addgroup.setLocationRelativeTo(this);
addgroup.setTitle("Adding New Group Wizard");
addgroup.setVisible(true);

How I can do it well?

Sorry for my English. Also I tried to read other questions about GroupLayouts but I can't solve it with them.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
joanlopez
  • 579
  • 1
  • 6
  • 17

1 Answers1

0

GroupLayout can only be used with one Container at a time, but you can have an arbitrary number of Container instances each having its own GroupLayout. In this example, try adding a third instance of GroupPanel.

    f.add(new GroupPanel(3));

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045