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...
Code Java:
//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?
Re: Preventing a JFrame from Being Iconified
You don't mention how you are creating your dialog, but what about using a modal JDialog?
Re: Preventing a JFrame from Being Iconified
Quote:
Originally Posted by
copeg
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...
Code Java:
public class NewTournamentGUI extends JFrame
{
//... ...
public NewTournamentGUI
{
super("New Tournament");
//... ...
}
//... ...
}
...and now it's like this...
Code Java:
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!