MDI Application in java

1k views Asked by At

I am making a MDI application in java using netbeans. the issue is that i have two buttons: Add employee and search employee. When i click Add employee, the internal frame for add employee opens up in the desktop pane, and when i click search employee it gets behind the earlier frame and is not visible until i exit the first frame. I want that if desktop pane is not empty then earlier internal frame should be disposed on click of the other button. Plese help me out

This is the code: Here JP is variable name for desktop pane.

private void BAddEmpActionPerformed(java.awt.event.ActionEvent evt) {
        o=new EntryEmp();
        JP.add(o);
        o.setVisible(true);  
    }                                       

    private void BSearchEmpActionPerformed(java.awt.event.ActionEvent evt) {
        Employee_search ob1=new Employee_search();
        JP.add(ob1);
        ob1.setVisible(true);        
    }                                
2

There are 2 answers

0
MadProgrammer On

After you've added the new JInternalFrame and made it visible call JInternalFrame#toFront

0
Continuity8 On

I think you should be able to set the first panes visibility to false:

private void BSearchEmpActionPerformed(java.awt.event.ActionEvent evt) {
    Employee_search ob1=new Employee_search();
    JP.add(ob1);
    ob1.setVisible(true);
    if (o != null && o.getVisible == true){
        o.setVisible(false);
        //and possibly kill it:
        o = null;
    }