Help Menu - opens frame which does not go to front
- From: "johnmmcparland" <johnmmcparland@xxxxxxxxxxxxxx>
- Date: 29 Aug 2006 03:16:41 -0700
Hi all,
I'm using a JFrame to display help content in a JEditorPane. The help
frame is started up when the user clicks on the "Help" menu.
Unfortunately, the help frame does not have focus nor is it at the
front.
Good examples of the effect I'm looking for are in Firefox and Internet
Explorer. In Firefox, go to Help then Help Contents. In IE go to Help
then Contents and Index.
A small example of my current code is below.
package helpMenu;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
public class MyWindow extends JFrame
{
public MyWindow()
{
// JFrame settings.
setTitle("Help Menu Demo");
setSize(800,600);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Menu bar / menus.
JMenuBar menuBar= new JMenuBar();
JMenu help= new JMenu("Help");
help.addMenuListener(new MListener("Help"));
menuBar.add(help);
setJMenuBar(menuBar);
setVisible(true);
}
// Inner class to handle JMenu actions.
private class MListener implements MenuListener
{
String name;
public MListener(String nm)
{
name= nm;
}
// Invoked when the menu is selected.
public void menuSelected(MenuEvent me)
{
if (name.equals("Help"))
{
JFrame helpFrame= new JFrame("Help");
helpFrame.setSize(200,500);
JEditorPane helpContent= new JEditorPane();
helpFrame.add(helpContent);
helpFrame.setVisible(true);
}
}
// Invoked when the menu is cancelled.
public void menuCanceled(MenuEvent me)
{
}
// Invoked when the menu is deselected.
public void menuDeselected(MenuEvent me)
{
}
}
public static void main(String[] args)
{
new MyWindow();
}
}
thanks,
john
.
- Follow-Ups:
- Re: Help Menu - opens frame which does not go to front
- From: johnmmcparland
- Re: Help Menu - opens frame which does not go to front
- Prev by Date: jdbTable select column
- Next by Date: how to refresh jComboBox in popupMenuWillBecomeVisible
- Previous by thread: jdbTable select column
- Next by thread: Re: Help Menu - opens frame which does not go to front
- Index(es):
Relevant Pages
|