¿Cómo minimizar una ventana JFrame desde Java?


En mi aplicación Java, tengo una ventana JFrame, ¿cómo puedo minimizarla desde mi programa Java ?

Author: cubanacan, 2010-10-19

6 answers

Minimizar con frame.setState(Frame.ICONIFIED)

Restaurar con frame.setState(Frame.NORMAL)

 46
Author: Brad Mace,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-10-19 04:33:43

Minimizar:

frame.setState(Frame.ICONIFIED);

Otra forma de minimizar:

frame.setExtendedState(JFrame.ICONIFIED);

Tamaño normal:

frame.setState(Frame.NORMAL);

Otra forma de tamaño normal:

frame.setExtendedState(JFrame.NORMAL);

Maximizar:

frame.setState(Frame.MAXIMIZED_BOTH);

Otra forma de maximizar:

frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

Maximiza la pantalla completa:

GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
try { device.setFullScreenWindow((Window) frame); } finally { device.setFullScreenWindow(null); }

Refiérase a la JFrame documentación para más información.

 11
Author: Arin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-16 22:32:28

Puedes hacer esto de dos maneras

JFrame frame = new JFrame("test");
 frame.setExtendedState(JFrame.ICONIFIED);  // one way


    frame.setState(JFrame.ICONIFIED); // another way
 9
Author: ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-19 09:08:40

Otro enfoque

frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_ICONIFIED));
 1
Author: OscarMike,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-13 13:04:28

Si está tratando de codificar para un evento de un componente, intente el código a continuación. Y asegúrese de que la clase que se incluye este código se extiende por Frame class

private void closeMouseClicked(java.awt.event.MouseEvent evt){                        
    this.setState(1);
}

O crear una instancia de una clase Frame y llamar a setState(1);

 -1
Author: Rusiru Adithya Samarasinghe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-12 14:17:09

Puede utilizar el siguiente código:

this.setState(YourJFrame.ICONIFIED);

Y puedes usar este código para maximizarlo:

this.setExtendedState(MAXIMIZED_BOTH);
 -1
Author: Buddhi Kavindra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-12 09:21:42