Skip to main content

Adding a "?" to the title bar of a JFrame

4 replies [Last post]
joecole
Offline
Joined: 2003-06-10

My user's would like to be able to use a "?" for my applications. For the life of me I have not been able to figure out how to give them this.

So, instead, I made a right click on any component that will display context sensitive help. They like this, but I still don't see why we can't have this option.

Is there any portable way to do this with Swing?

If I could do it I could easily hook it up with the same context sensitive help in a few lines. Has anyone been able to do this with non-native code? I am developing primarily for windows, but I do not really want a native solution.

Joe Cole

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shan-man
Offline
Joined: 2006-02-17

Hi Joe,

> My user's would like to be able to use a "?" for my
> applications. For the life of me I have not been able
> to figure out how to give them this.
>
> So, instead, I made a right click on any component
> that will display context sensitive help. They like
> this, but I still don't see why we can't have this
> option.
>
> Is there any portable way to do this with Swing?
>
> If I could do it I could easily hook it up with the
> same context sensitive help in a few lines. Has
> anyone been able to do this with non-native code? I
> am developing primarily for windows, but I do not
> really want a native solution.
>
> Joe Cole

Interesting...I know exactly what you're talking about, as I've seen dialogs like this on Windows many times. I think it would be great if we offered this. I'm going to send a message internally to determine the possibility.

I'll respond back to the forum later.

Shannon

joecole
Offline
Joined: 2003-06-10

Shannon,

thanks for the reply.

It really would be a good feature for usability, as most users of windows based systems [in my experience] know about the "What's this" feature.

The problem is, how do you have context sensitive help for a swing application? I would think that it could work on many levels, but one way could be by naming components. At the moment all my components have a relationship to the model they are entering for, and these models use metadata to describe any help etc.

I simply use a custom JTextPane popup, with a UI the same as TooltipUI to show context help, but the programmer has the option of using popup, javahelp or html help.

Thoughts?

Joe

sma
Offline
Joined: 2003-06-10

With 1.4.x, Swing can draw the window decorations (borders, title, widgets) for certain looks itself. I just checked, the builtin Windows look cannot, but the Metal look can. Call "JFrame.setDefaultLookAndFeelDecorated(true);" before opening the first JFrame. Now look at javax.swing.plaf.metal.MetalRootPaneUI#installClientDecorations(JRootPane). It will create a MetalTitlePane which implements the titled window border with widgets and menu. Because all interesting methods in MetalRootPaneUI is still declared private, you need to copy that file and change the reference to MetalTitlePane to provide your own pane. Then create your own look variant based on that modified MetalRootPane. Finally, you can now add a help button to the set of minimize, maximize and close button.

You need then to add an action to that help button to change the mouse, wait for a mouse click on some component or for ESC or a focus out event. To receive the click you'd probbaly need to either add a new mouse listener in front of all other listeners for all clickable components in the whole frame which then consumes the click so that you basically overwrite the normal behavior. Or you need a special RootPane subclass which directly processes the click before it goes down the component hierachy. Eventually, you know the clicked component and you can call an action to show the context help. IIRC, Windows also supports Shift+F1 or Ctrl+F1 to open the same help for the currently focussed widget.

Stefan

joecole
Offline
Joined: 2003-06-10

> With 1.4.x, Swing can draw the window decorations
> (borders, title, widgets) for certain looks itself.
> I just checked, the builtin Windows look cannot, but
> the Metal look can.

This is the problem - i am developing primarily for windows desktop.

Any other ways? I have the code sitting there to do the context sensitive help, but no way to do the ? button.

Joe