# How do I Make an Ignition appication get the focus?

**URL:** <https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630>\
**Category:** Ignition\
**Created:** [March 11, 2010, 9:16pm UTC](https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630 "2010-03-11T21:16:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ISDProj](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@ISDProj](https://forum.inductiveautomation.com/u/ISDProj)\
**Post date:** [March 11, 2010, 9:16pm UTC](https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630/1 "2010-03-11T21:16:01Z")

</div>

I am desiging an application in Ignition which will be running on a PC (Win XP and/or Win7) with other applications simultaneously.  
The problem I have is that I want the application to “steal the focus” (I.E. pop-up) when certain events occur (tag change or whatever), but I can’t work out how to do this.

Any help, pointers, or suggestions on how I can achieve this would be greatly appreciated

Thanks in advance.

Peter

---

<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:** [March 11, 2010, 10:27pm UTC](https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630/2 "2010-03-11T22:27:41Z")

</div>

A script like this will make the application flash on the taskbar, is that what you mean?

[code]from java.awt import Window  
from javax.swing import SwingUtilities

window = SwingUtilities.getAncestorOfClass(Window, event.source)  
window.toFront()[/code]

You need an event object from a component for that script to work…upon what event did you want this to happen?

[edit] never mind, you said above - on a tag change. That script won’t work on a client-side tag change script. Hold tight…

---

<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:** [March 11, 2010, 10:33pm UTC](https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630/3 "2010-03-11T22:33:17Z")

</div>

Ok, to do this from a tag-change script is a little stranger, because you don’t have a very straight-forward hook into the windowing system. The following works, but relies on at least one window being open. This is a fairly good assumption, because a Vision client with no windows open is pretty useless.

[code]from java.awt import Window  
from javax.swing import SwingUtilities

allWindows = system.gui.getOpenedWindows()

if len(allWindows)\>0:  
topWindow = SwingUtilities.getAncestorOfClass(Window, allWindows[0])  
topWindow.toFront()[/code]

---

<div class="post-metadata">

**Author:** ![ISDProj](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@ISDProj](https://forum.inductiveautomation.com/u/ISDProj)\
**Post date:** [March 11, 2010, 11:23pm UTC](https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630/4 "2010-03-11T23:23:24Z")

</div>

Thanks Carl, I’ll give it a try today & let you know if it works…

BTW I believe that since WinXP SP3 setting window.toFront() will only make it “flash” the toolbar icon on subsequent calls, but I haven’t tried that out yet. I may need to “play a bit” perhaps with the modal settings of the window (if accessible) to make the Pop-up happen consistently…

---

<div class="post-metadata">

**Author:** ![ISDProj](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@ISDProj](https://forum.inductiveautomation.com/u/ISDProj)\
**Post date:** [March 12, 2010, 8:06am UTC](https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630/5 "2010-03-12T08:06:28Z")

</div>

Argh!!! It’s moment like this I hate windows…

I was about to post to say It works wonderfully but it doesn’t.

I did have it swapping back to the application after several rehashes of the script but after exiting & restarting the client I’m back to “flashing the icon” ☹

I don’t want to have to write a dll just to call the user32 API function SetWindowPos()  
Any Ideas how I can get this swapping working reliably?

---

<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:** [March 12, 2010, 4:09pm UTC](https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630/6 "2010-03-12T16:09:11Z")

</div>

Looks like you’re not alone in this request. You can read about the various ins and outs of it on [this StackOverflow](http://stackoverflow.com/questions/309023/howto-bring-a-java-window-to-the-front) thread, and on this [forums.sun.com](http://forums.sun.com/thread.jspa?threadID=5124278) thread.

You should try setting:

`window.setAlwaysOnTop(1)
window.setAlwaysOnTop(0)`

---

<div class="post-metadata">

**Author:** ![ISDProj](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@ISDProj](https://forum.inductiveautomation.com/u/ISDProj)\
**Post date:** [March 13, 2010, 2:47pm UTC](https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630/7 "2010-03-13T14:47:14Z")

</div>

Thanks Carl. It worked a treat. 😃

This is what I ended up with

[code]#PJR 20100313  
#This Script forces the Ignition App to appear if not showing.  
#It works for both windowed & full screen launch modes  
from java.awt import Window  
from javax.swing import SwingUtilities  
from java.awt import Frame

allWindows = system.gui.getOpenedWindows()  
if len(allWindows)==0:  
#No Windows open? open one first  
system.nav.openWindow(“DowntimeEvents”)  
allWindows = system.gui.getOpenedWindows()

topWindow = SwingUtilities.getAncestorOfClass(Window, allWindows[0])  
state = topWindow.getExtendedState()  
state &= ~Frame.ICONIFIED  
topWindow.setExtendedState(state)  
topWindow.setAlwaysOnTop(1)  
topWindow.toFront()  
#topWindow.show()  
topWindow.setAlwaysOnTop(0)  
[/code]

Not sure if this is related to what I’m doing in the above script but I have had to add the code below to the “Logout” menu option

`try:
	system.security.logout()
except:
	system.util.exit(1)
`  
It is because there is a null pointer exception when you log out the 2nd time (first one always works) I can get to occur by:  
1.) showing a warning box on the screen (if a particular user role tries to Exit the application - Not from Shutdown-Intercept)  
2.) call the script above to “Logout”  
3.) log back in.  
4.) repeat from step 1 and the client app will exit on logout.  
This happens in both full screen and windowed modes. If you don’t catch the exception you end up with an empty “frame”

---

<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:** [March 15, 2010, 4:30pm UTC](https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630/8 "2010-03-15T16:30:15Z")

</div>

Glad you got the bring to front script working. I’ll look into that NPE you’re describing.

---

<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:** [March 15, 2010, 6:38pm UTC](https://forum.inductiveautomation.com/t/how-do-i-make-an-ignition-appication-get-the-focus/1630/9 "2010-03-15T18:38:56Z")

</div>

We’ve identified the problem with logging out - it has been fixed for the next release, 7.0.5
