# Minimize project on Button Click

**URL:** <https://forum.inductiveautomation.com/t/minimize-project-on-button-click/2156>\
**Category:** Archived Topics\
**Created:** [August 27, 2010, 6:39pm UTC](https://forum.inductiveautomation.com/t/minimize-project-on-button-click/2156 "2010-08-27T18:39:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.inductiveautomation.com/u/Ron)\
**Post date:** [August 27, 2010, 6:39pm UTC](https://forum.inductiveautomation.com/t/minimize-project-on-button-click/2156/1 "2010-08-27T18:39:41Z")

</div>

I would like to minimize my FPMI project in code on a button click or menu item selection. Is this possible? I am running a project in full screen mode and allow the user to link to an email page that is opened in a browser window. When I do that the FPMI project is minimized and the user can interact with their email. When they minimize the email, then they have no way to get back to it again without using windows controls. I would like to allow them to minimize the project, which would display their email browser again.

Thanks,  
Ron

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [August 30, 2010, 4:31pm UTC](https://forum.inductiveautomation.com/t/minimize-project-on-button-click/2156/2 "2010-08-30T16:31:32Z")

</div>

There aren’t any built-in controls to switch between various window states (full-screen, normal, minimized, etc), but like so many things, you should be able to do this with some clever scripting.

[code]from javax.swing import JFrame  
from javax.swing import SwingUtilities  
from java.awt import GraphicsEnvironment

# Grab the parent frame

frame = SwingUtilities.getAncestorOfClass(JFrame, event.source)

# Get the screen device

screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()

# Exit full-screen mode

screen.setFullScreenWindow(None)

# Minimize the frame. 1 == java.awt.Frame.ICONIFIED

frame.setExtendedState(1)[/code]

Hope this helps,

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.inductiveautomation.com/u/Ron)\
**Post date:** [August 30, 2010, 5:34pm UTC](https://forum.inductiveautomation.com/t/minimize-project-on-button-click/2156/3 "2010-08-30T17:34:59Z")

</div>

That works great Carl, but when I restore the window it is no longer in full screen mode. Is it possible to reset it to full screen so when they click on the minimized project, it returns to full screen mode?

Thanks,  
Ron

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [August 30, 2010, 6:27pm UTC](https://forum.inductiveautomation.com/t/minimize-project-on-button-click/2156/4 "2010-08-30T18:27:03Z")

</div>

Ok, now things get really fun. In order to do this, you add a window listener to the frame that listens for when the frame becomes “deiconified” (restored), and then re-enters fullscreen mode. You only want to add this listener the 1st time you minimize, after that it will stay on the window for the lifetime of the client listening for deiconified events.

[code]from javax.swing import JFrame  
from javax.swing import SwingUtilities  
from java.awt import GraphicsEnvironment  
from java.awt.event import WindowAdapter

# Grab the parent frame

frame = SwingUtilities.getAncestorOfClass(JFrame, event.source)

# Get the screen device

screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()

# Exit full-screen mode

screen.setFullScreenWindow(None)

# Minimize the frame. 1 == java.awt.Frame.ICONIFIED

frame.setExtendedState(1)  
print “Exiting fullscreen mode”

# If this is the 1st time we’ve ever been run, add a listener

# to the frame to go back into fullscreen mode when we get

# restored from minimized mode

global firstRun  
try:  
if firstRun:  
firstRun=0  
except NameError:  
firstRun=1

class ReFullscreen(WindowAdapter):  
def windowDeiconified(self, evt):  
def goFull(event=evt):  
from javax.swing import JFrame  
from javax.swing import SwingUtilities  
from java.awt import GraphicsEnvironment  
# Grab the parent frame  
frame = SwingUtilities.getAncestorOfClass(JFrame, event.source)  
# Get the screen device  
screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()  
# Re-enter full-screen mode  
print “Re-entering fullscreen mode”  
screen.setFullScreenWindow(frame)

```
	import fpmi
	fpmi.system.invokeLater(goFull)

```

if firstRun:  
print “Adding window listener to re-enter fullscreen mode”  
frame.addWindowListener(ReFullscreen())[/code]
