# Add a button to window frames

**URL:** <https://forum.inductiveautomation.com/t/add-a-button-to-window-frames/9566>\
**Category:** General Discussion\
**Created:** [January 19, 2015, 5:39pm UTC](https://forum.inductiveautomation.com/t/add-a-button-to-window-frames/9566 "2015-01-19T17:39:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![steven.elam](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.elam/32/4797_2.png) [@steven.elam](https://forum.inductiveautomation.com/u/steven.elam)\
**Post date:** [January 19, 2015, 5:39pm UTC](https://forum.inductiveautomation.com/t/add-a-button-to-window-frames/9566/1 "2015-01-19T17:39:57Z")

</div>

Is there a way to add a button to window frames next to the maximize and close buttons? I would like to add context-sensitive help buttons to my windows.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 19, 2015, 7:12pm UTC](https://forum.inductiveautomation.com/t/add-a-button-to-window-frames/9566/2 "2015-01-19T19:12:36Z")

</div>

And on a related thought, could we add something to the builtin help menu? (sorry for the minor hijack)

---

<div class="post-metadata">

**Author:** ![steven.elam](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steven.elam/32/4797_2.png) [@steven.elam](https://forum.inductiveautomation.com/u/steven.elam)\
**Post date:** [January 27, 2015, 5:34pm UTC](https://forum.inductiveautomation.com/t/add-a-button-to-window-frames/9566/3 "2015-01-27T17:34:19Z")

</div>

I was hoping a customer support engineer or a developer could chime in on this. Thanks.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 31, 2015, 10:52pm UTC](https://forum.inductiveautomation.com/t/add-a-button-to-window-frames/9566/4 "2015-01-31T22:52:50Z")

</div>

Hi Steven, Jordan,

Adding icons to the window decorator’s titlebar is quite a rathole (involving OS-specific look-and-feel implementations). However, you can add a menubar to your windows, and you can get at the help menu of the main window.

Some example code to put on the internalFrameOpened event of a window:

[code]from javax.swing import JMenuBar, JMenu, JMenuItem  
from java.awt.event import KeyEvent  
w = event.source  
menu = w.menuBar  
if not menu:  
menu = JMenuBar()  
myMenu = JMenu(“MyMenuText”)  
myMenu.setMnemonic(KeyEvent.VK\_M)  
menu.add(myMenu)  
myAction = JMenuItem(“DoSomething”, KeyEvent.VK\_D)  
def myActionSub(event, origin=event.source):  
# Do something with the origin window “origin”  
print "Here I am in window "+origin.name  
myAction.addActionListener(myActionSub)  
myMenu.add(myAction)  
w.menuBar = menu

topMenu = w.parent.rootPane.menuBar  
helpMenu = list(topMenu.subElements)[-1]  
print helpMenu  
if helpMenu.label==‘Help’:  
first = helpMenu.popupMenu.getComponent(0)  
print first  
if first.label != “MyTopAction”:  
print “Adding MyTopAction”  
myTopAction = JMenuItem(“MyTopAction”)  
def myTopActionSub(event):  
# Do something at the application level  
print “Here I am in the Application’s Menu”  
myTopAction.addActionListener(myTopActionSub)  
helpMenu.popupMenu.insert(myTopAction, 0)  
else:  
print “MyTopAction Already loaded”  
[/code]

A nuance to consider is that there’s no way to get at the application’s JRootPane without having a window object to start from. The scripting environment available for the project startup event has nothing useful here. So you need “fix” the main menu when an inner window opens, and check to make sure you haven’t already loaded it. Any window set to auto-open on project startup would be a good candidate.
