Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: JInternalFrame Only Show one Window

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default JInternalFrame Only Show one Window

    Window1 is JInternalFrame
    I want when the menu item is clicked, the JInternalFrame only can show one window, if we click the menu item again, i will detect that JInternalFrame is exist, how to do that?

    Here is my code :
        private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
            // TODO add your handling code here:
            Window1 frm1 = new Window1();
            if (frm1.isShowing()) {
                JOptionPane.showMessageDialog(null, "yo");
            } else {
                desktopPane.add(frm1);
                frm1.show();
            }
        }

    it still showing new Window everytime i click the menu item


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: JInternalFrame Only Show one Window

    Quote Originally Posted by sadaharu View Post
    it still showing new Window everytime i click the menu item
    That is what the code says to do. thing t = new thing;
    if you don't want a new one each time don't make a new one each time, keep a reference to the old one

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: JInternalFrame Only Show one Window

    Quote Originally Posted by jps View Post
    That is what the code says to do. thing t = new thing;
    if you don't want a new one each time don't make a new one each time, keep a reference to the old one
    how to keep it as it old one dude?

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: JInternalFrame Only Show one Window

    In the posted method, frm1 is declared as a local variable. (Defined within the scope of the method)

    Any variable created within a method is garbage when the method returns. (Either by hitting a return statement or reaching the } closing the method)

    Declare the variable as a class variable. Check the link and post any questions you may have left

Similar Threads

  1. Applet viewer window is diplaying in fron of the current window every time
    By jsreddy99 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 24th, 2013, 07:16 AM
  2. Replies: 1
    Last Post: December 17th, 2011, 03:32 AM
  3. Replies: 1
    Last Post: September 26th, 2011, 07:23 AM
  4. Beginner: Show Image in Label when Results Show Up
    By Big Bundy in forum Java Theory & Questions
    Replies: 3
    Last Post: April 4th, 2011, 02:43 PM
  5. How do i show all the values in one window(JOptionPane)??
    By Antonioj1015 in forum AWT / Java Swing
    Replies: 1
    Last Post: November 25th, 2009, 09:24 PM