Add a button to window frames

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.

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

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

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.