Re: Help Menu - opens frame which does not go to front
- From: "johnmmcparland" <johnmmcparland@xxxxxxxxxxxxxx>
- Date: 29 Aug 2006 06:17:09 -0700
Update on this,
I've got the help to the front by making it a JDialog and setting
toFront and the location. But I cannot set it to be the currently
selected window. Any ideas?
[code]
package helpMenu;
import javax.swing.JDialog;
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
{
private JDialog helpDialog;
private JEditorPane helpContent;
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);
// The help dialog.
setupHelpDialog();
setVisible(true);
}
private void setupHelpDialog()
{
helpDialog= new JDialog(this, "MyWindow Help", false);
helpDialog.setSize(250,700);
helpDialog.setLocation(this.getSize().width,this.getSize().height-350);
helpContent= new JEditorPane();
helpDialog.add(helpContent);
helpDialog.setVisible(false);
}
// 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"))
{
helpDialog.toFront();
helpDialog.setVisible(true);
}
}
// Invoked when the menu is cancelled.
public void menuCanceled(MenuEvent me)
{
helpDialog.setVisible(false);
}
// Invoked when the menu is deselected.
public void menuDeselected(MenuEvent me)
{
}
}
public static void main(String[] args)
{
new MyWindow();
}
}
[/code]
johnmmcparland wrote:
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: Andrew Thompson
- Re: Help Menu - opens frame which does not go to front
- References:
- Help Menu - opens frame which does not go to front
- From: johnmmcparland
- Help Menu - opens frame which does not go to front
- Prev by Date: how to refresh jComboBox in popupMenuWillBecomeVisible
- Next by Date: Re: Help Menu - opens frame which does not go to front
- Previous by thread: Help Menu - opens frame which does not go to front
- Next by thread: Re: Help Menu - opens frame which does not go to front
- Index(es):
Relevant Pages
|