如何从Java最小化JFrame窗口?

时间:2021-01-08 07:17:10

In my Java app, I have a JFrame window, how can I minimize it from my Java program ?

在我的Java应用程序中,我有一个JFrame窗口,如何从Java程序中最小化它?

6 个解决方案

#1


45  

minimize with frame.setState(Frame.ICONIFIED)

使用frame.setState(Frame.ICONIFIED)进行最小化

restore with frame.setState(Frame.NORMAL)

使用frame.setState(Frame.NORMAL)恢复

#2


10  

Minimize:

最小化:

frame.setState(Frame.ICONIFIED);

Another way to minimize:

另一种最小化的方法:

frame.setExtendedState(JFrame.ICONIFIED);

Normal size:

正常尺寸:

frame.setState(Frame.NORMAL);

Another way to normal size:

正常尺寸的另一种方法:

frame.setExtendedState(JFrame.NORMAL);

Maximize:

最大化:

frame.setState(Frame.MAXIMIZED_BOTH);

Another way to maximize:

最大化的另一种方法:

frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

Full Screen maximize:

全屏最大化:

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

Refer to the JFrame documentation for more information.

有关更多信息,请参阅JFrame文档。

#3


8  

you can do this in two ways

你可以用两种方式做到这一点

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


    frame.setState(JFrame.ICONIFIED); // another way

#4


0  

Another approach

另一种方法

frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_ICONIFIED));

#5


-1  

If you are trying to code for a event of a component then try code below. And make sure the class which this code is included is extended by Frame class

如果您尝试编写组件事件的代码,请尝试下面的代码。并确保包含此代码的类由Frame类扩展

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

Or create an instance of a Frame class and call setState(1);

或者创建一个Frame类的实例并调用setState(1);

#6


-1  

You can use following code:

您可以使用以下代码:

this.setState(YourJFrame.ICONIFIED);

And you can use this code to maximize it:

并且您可以使用此代码来最大化它:

this.setExtendedState(MAXIMIZED_BOTH);

#1


45  

minimize with frame.setState(Frame.ICONIFIED)

使用frame.setState(Frame.ICONIFIED)进行最小化

restore with frame.setState(Frame.NORMAL)

使用frame.setState(Frame.NORMAL)恢复

#2


10  

Minimize:

最小化:

frame.setState(Frame.ICONIFIED);

Another way to minimize:

另一种最小化的方法:

frame.setExtendedState(JFrame.ICONIFIED);

Normal size:

正常尺寸:

frame.setState(Frame.NORMAL);

Another way to normal size:

正常尺寸的另一种方法:

frame.setExtendedState(JFrame.NORMAL);

Maximize:

最大化:

frame.setState(Frame.MAXIMIZED_BOTH);

Another way to maximize:

最大化的另一种方法:

frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

Full Screen maximize:

全屏最大化:

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

Refer to the JFrame documentation for more information.

有关更多信息,请参阅JFrame文档。

#3


8  

you can do this in two ways

你可以用两种方式做到这一点

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


    frame.setState(JFrame.ICONIFIED); // another way

#4


0  

Another approach

另一种方法

frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_ICONIFIED));

#5


-1  

If you are trying to code for a event of a component then try code below. And make sure the class which this code is included is extended by Frame class

如果您尝试编写组件事件的代码,请尝试下面的代码。并确保包含此代码的类由Frame类扩展

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

Or create an instance of a Frame class and call setState(1);

或者创建一个Frame类的实例并调用setState(1);

#6


-1  

You can use following code:

您可以使用以下代码:

this.setState(YourJFrame.ICONIFIED);

And you can use this code to maximize it:

并且您可以使用此代码来最大化它:

this.setExtendedState(MAXIMIZED_BOTH);