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 3 of 3

Thread: Preventing a JFrame from Being Iconified

  1. #1
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Preventing a JFrame from Being Iconified

    Hi!

    I'm creating a program to manage the March Madness stuff my family does, so I can expand my knowledge of Java.

    Right now, I'm encountering a problem with the "New Tournament" dialog box... In the main program's GUI, the user clicks a menu item "New tournament..." and then the "New Tournament" dialog box appears. However, I don't want to allow the user to click out of the "New Tournament" dialog box, or allow them to iconify it.

    Right now, I'm using a WindowListener...

    //See windowDeactivated and windowIconified
    private class NewTournamentGUIWindowListener implements WindowListener
    {
     
       public void windowClosing(WindowEvent e)
       {
     
          //This code is not part of the problem
          MainGUI.newTournamentWindowOpened = false;
          MainGUI.setStatus();
     
       }
     
       public void windowClosed(WindowEvent e)
       {
     
     
     
       }
     
       public void windowOpened(WindowEvent e)
       {
     
     
     
       }
     
       public void windowDeactivated(WindowEvent e)
       {
     
          /*
           * Whenever the user clicks outside the JFrame
           * it is deiconified and refocused.
          */
     
          setExtendedState(JFrame.NORMAL);
          requestFocus();
     
       }
     
       public void windowActivated(WindowEvent e)
       {
     
     
     
       }
     
       public void windowDeiconified(WindowEvent e)
       {
     
     
     
       }
     
       public void windowIconified(WindowEvent e)
       {
     
          /*
           * Whenever the user attempts to iconify the window
           * it immediately deiconifies itself; however, this process
           * looks sloppy. How can I deactivate the "Minimize" icon
           * that occurs at the top right of the JFrame?
          */
     
          setExtendedState(JFrame.NORMAL);
     
       }
    }

    Does anyone know how to prevent a window that I've created from being iconified?
    Last edited by snowguy13; November 26th, 2011 at 11:27 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Preventing a JFrame from Being Iconified

    You don't mention how you are creating your dialog, but what about using a modal JDialog?

  3. The Following User Says Thank You to copeg For This Useful Post:

    snowguy13 (November 27th, 2011)

  4. #3
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Preventing a JFrame from Being Iconified

    Quote Originally Posted by copeg View Post
    You don't mention how you are creating your dialog, but what about using a modal JDialog?
    Okay, I did some research on modal dialogs, and appended my code a little. Before, it was like this...

    public class NewTournamentGUI extends JFrame
    {
     
       //... ...
     
       public NewTournamentGUI
       {
     
          super("New Tournament");
     
          //... ...
     
       }
     
       //... ...
     
    }

    ...and now it's like this...

    public class NewTournamentGUI extends JDialog
    {
     
       //... ...
     
       public NewTournamentGUI
       {
     
          super(new JFrame(), "New Tournament", Dialog.ModalityType.APPLICATION_MODAL);
     
          //... ...
     
       }
     
       //... ...
     
    }

    And now it works just the way I wanted to! Thank you very much!
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

Similar Threads

  1. using objects from one jFrame on a different jFrame
    By Taskeen in forum AWT / Java Swing
    Replies: 3
    Last Post: September 14th, 2011, 08:51 AM
  2. connecting jframe to another jframe
    By ajtambalo in forum Member Introductions
    Replies: 2
    Last Post: May 11th, 2011, 11:24 AM
  3. Pop-out box using a JFrame.
    By ShaunB in forum Java Theory & Questions
    Replies: 6
    Last Post: April 28th, 2011, 12:03 PM
  4. Replies: 1
    Last Post: November 9th, 2010, 09:58 AM
  5. JFrame help
    By Uden in forum AWT / Java Swing
    Replies: 0
    Last Post: August 14th, 2009, 01:37 PM