Results 1 to 4 of 4
  1. #1
    OmarMusallam is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default JDesktopPanel & JInternalFrame

    i have hundreds of JInternalFrames control by JMenu and JdesktopPanel, each button add JInternalFrame to DesktopPanel, my problem is when i press the same button twice, it opens the same screen twice, how can i validate if the screen is alive before open it another time?

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    JInternalFrame has an isClosed() method to determine whether the frame has been close.

    JInternalFrame (Java 2 Platform SE v1.4.2))

  3. #3
    OmarMusallam is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default

    well, i tried it but let me show u part of the code :

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEve nt evt) {
    JInternalFrameEx usrmain= new JInternalFrameEx();
    jDesktopPane1.add(usrmain);
    usrmain.setVisible(true);

    }


    this is the listener funtion, it creates new object of the frame then added to the desktoppane. so each time this function called , new instance of JInternalFrameEx will be created so when i validate isClose() . it will be pointing to the new instance , where the old instance still opened

    i hope you got my point

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by OmarMusallam View Post
    well, i tried it but let me show u part of the code :

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEve nt evt) {
    JInternalFrameEx usrmain= new JInternalFrameEx();
    jDesktopPane1.add(usrmain);
    usrmain.setVisible(true);

    }


    this is the listener funtion, it creates new object of the frame then added to the desktoppane. so each time this function called , new instance of JInternalFrameEx will be created so when i validate isClose() . it will be pointing to the new instance , where the old instance still opened

    i hope you got my point
    Why not make that listener remember whether or not it created that JInternalFrame before? Something like this will do:

    Java Code:
    class YourListener implements ActionListener {
       private JInternalFrame usrmain; // remembers the JInternalFrame
       public void actionPerformed(ActionEvent ae) {
          if (usrmain == null) { // not yet created?
              usrmain= new JInternalFrameEx();
              jDesktopPane1.add(usrmain);
              usrmain.setVisible(true);
          }
       }
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. jInternalFrame
    By kiranjava in forum Advanced Java
    Replies: 1
    Last Post: 05-20-2010, 12:04 PM
  2. How to reload JInternalFrame
    By chyrl in forum AWT / Swing
    Replies: 42
    Last Post: 04-16-2010, 01:29 PM
  3. How to refresh my JInternalFrame upon CUD
    By chyrl in forum AWT / Swing
    Replies: 2
    Last Post: 04-01-2010, 04:22 PM
  4. JInternalFrame Help
    By collin389 in forum New To Java
    Replies: 2
    Last Post: 03-16-2010, 12:23 AM
  5. JInternalFrame Help
    By collin389 in forum AWT / Swing
    Replies: 1
    Last Post: 03-15-2010, 09:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •