Help Menu - opens frame which does not go to front



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

.



Relevant Pages

  • Re: PaintComponent Does not Fire
    ... public class ViewGraphical extends JFrame implements Observer ... private Controller controller; ... Image imgDog = Toolkit.getDefaultToolkit.getImage; ... public void update ...
    (comp.lang.java.gui)
  • Re: Canvas
    ... I added a Canvas in a JFrame. ... public void actionPerformed{ ... public class MyCanvas2 extends Canvas{ ...
    (comp.lang.java.programmer)
  • Re: GUI and Thread
    ... > To avoid this, I execute a packroutine on the frame, but then ... > This is because there is not content in the TextArea and TextField. ... Call setVisible/after/ adding all components to your JFrame. ...
    (comp.lang.java.programmer)
  • Re: Drawing Image
    ... put on to a JFrame which has several internal frames. ... public class test extends JPanel { ... public void paintComponent{ ...
    (comp.lang.java.help)
  • Re: GUI....Controlling Control Buttons ....
    ... > When I start the JFrame instance it shows the Window but does not show ... > all the components of the frame gets collected in one part of the ... > public class Chat extends JFrame implements Runnable { ...
    (comp.lang.java.gui)