Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Click on jmenuitem open the jinternalframe..

  1. #1
    Join Date
    Jul 2010
    Posts
    38
    Rep Power
    0

    Question Click on jmenuitem open the jinternalframe..

    Hi...

    I m created one simple frame with menu in netbeans.
    and also created jinternalframe in the same package.

    whenever i clicked on menuitem Its open Jinternalframe manytimes..

    for example : File menu -> File1(Menuitem)

    when i click on file1 its open jinternalframe. again i click on file1 its open the new jinternalframe..
    so i don't want to open new internalframe when the same frame is open.




    This is my code to open jinternal frame on mouse clicked on menu.

    XML Code:
    private void Jinternalframe1_MenuMouseClicked(java.awt.event.MouseEvent evt) {
            Jinternalframe1 jn = new Jinternalframe1();
            this.desktopPane.add(jn);
            jn.show();
    }
    help me to open only 1 frame at a time when the jinternalframe1 are open on clicking on menuitem its doesn't open once again on click same menuitem.

    Thanx
    mcajavaprogramer
    Last edited by mcajavaprogramer; 05-11-2012 at 08:58 AM.

  2. #2
    Join Date
    Jul 2010
    Posts
    38
    Rep Power
    0

    Default Re: Click on jmenuitem open the jinternalframe..

    There is no-body who have this solution about this question..?

  3. #3
    shall is offline Senior Member
    Join Date
    Apr 2012
    Posts
    199
    Rep Power
    0

    Default Re: Click on jmenuitem open the jinternalframe..

    What about creating a JInternalFrames class member variable. Then, in the mouse click function, only create the internal frame if the member variable is null.

    Java Code:
    Jinternalframe1 jn = null;
    private void Jinternalframe1_MenuMouseClicked(java.awt.event.MouseEvent evt) {
            if (jn == null) {
               jn = new Jinternalframe1();
               this.desktopPane.add(jn);
               jn.show();
            }
    }

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Click on jmenuitem open the jinternalframe..

    First, the correct listener for a JMenuItem is ActionListener, not MouseListener.

    A better programming idiom is to disable the menu item when the internal frame is opened, and enable it when the internal frame is closed. You would use an InternalFrameListener for that, probably extending InternalFrameAdapter.

    Another possibility, if you want to give the user the option to close the internal frame from the menu, is to use a JCheckBoxMenuItem.

    Read the API for those classes and follow any links to the Oracle tutorials on 'How to Use ...'

    db

    edit: You've probably already been told this, but the NetBeans (or any other) visual designer is categorically not a beginners' tool. Unless you aim to make a career out of Swing GUI design (not likely, now that JavaFX has started to take over the market) it's just not worht the time and effort to learn all its quirks. That time and effort is much better spent in reading tutorials and learning how to code a Swing GUI by hand.
    Last edited by DarrylBurke; 05-16-2012 at 08:26 AM.
    mcajavaprogramer likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Join Date
    Jul 2010
    Posts
    38
    Rep Power
    0

    Default Re: Click on jmenuitem open the jinternalframe..

    Quote Originally Posted by DarrylBurke View Post
    First, the correct listener for a JMenuItem is ActionListener, not MouseListener.

    A better programming idiom is to disable the menu item when the internal frame is opened, and enable it when the internal frame is closed. You would use an InternalFrameListener for that, probably extending InternalFrameAdapter.

    Another possibility, if you want to give the user the option to close the internal frame from the menu, is to use a JCheckBoxMenuItem.

    Read the API for those classes and follow any links to the Oracle tutorials on 'How to Use ...'

    db

    edit: You've probably already been told this, but the NetBeans (or any other) visual designer is categorically not a beginners' tool. Unless you aim to make a career out of Swing GUI design (not likely, now that JavaFX has started to take over the market) it's just not worht the time and effort to learn all its quirks. That time and effort is much better spent in reading tutorials and learning how to code a Swing GUI by hand.


    Thank you very much...

  6. #6
    Join Date
    Jul 2010
    Posts
    38
    Rep Power
    0

    Default Re: Click on jmenuitem open the jinternalframe..

    Quote Originally Posted by shall View Post
    What about creating a JInternalFrames class member variable. Then, in the mouse click function, only create the internal frame if the member variable is null.

    Java Code:
    Jinternalframe1 jn = null;
    private void Jinternalframe1_MenuMouseClicked(java.awt.event.MouseEvent evt) {
            if (jn == null) {
               jn = new Jinternalframe1();
               this.desktopPane.add(jn);
               jn.show();
            }
    }
    Thank you very much ...:)

Similar Threads

  1. How to open .ods file on button click event
    By Anagha in forum New To Java
    Replies: 15
    Last Post: 07-08-2012, 09:10 PM
  2. Replies: 6
    Last Post: 03-19-2011, 03:24 AM
  3. Open the file by mouse click
    By Chika in forum New To Java
    Replies: 3
    Last Post: 09-19-2010, 11:44 PM
  4. How we can open a file with a click in button
    By kostinio in forum AWT / Swing
    Replies: 2
    Last Post: 11-01-2009, 04:46 PM
  5. how to click a jbutton and open an url
    By katie in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 10:44 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
  •