Search code examples
javaswingjdialogswingx

Modal JDialog shows empty frame. Contained Panels are not showing


Okay so I've successfully created a modal JDialog and I used Netbeans GUI Builder to create panels to speed up the design. However, the modal JDialog doesn't show the panels it has, therefore empty. I don't know what to do next and I don't see any reason why it won't show up if the main container does show.

JDialog is expected to come up after 2 mouse clicks on JTable

enter image description here

What comes up is this.

enter image description here

instead of this (Update Curriculum Gui), below.

enter image description here

private void curriculumListJtblMouseClicked(java.awt.event.MouseEvent evt) {                                                
        int clickCount = evt.getClickCount();
        if (clickCount == 2) {
            UpdateCurriculumGui updateCurriculum = new UpdateCurriculumGui();
            updateCurriculum.setPreferredSize(new Dimension(1000, 650));
            updateCurriculum.setVisible(true);
            updateCurriculum.pack();
            updateCurriculum.setLocationRelativeTo(null);
        }
    }  

UpdateCurriculumGui on it's own class.

public class UpdateCurriculumGui extends javax.swing.JDialog {



    public UpdateCurriculumGui() {
        super(null, ModalityType.MODELESS);
        setAlwaysOnTop(true);
        setTitle("Update Curriculum Information");
    }
}

I hope you can help me because I haven't tried to use JDialogs before. I'd appreciate any suggestions.

Thanks.


Solution

  • you have to fill your dialog with content!

    public class UpdateCurriculumGui extends javax.swing.JDialog {
    
        public UpdateCurriculumGui() {
            super(null, ModalityType.APPLICATION_MODAL);
            //setAlwaysOnTop(true); set modal instead
            setTitle("Update Curriculum Information");
            add(new JLabel("i'm content!"));  //this is content!      
        }
    }
    

    see Dialog.ModalityType for details on MODELESS (shouldn't it be APPLICATION_MODAL ?)