AbstractAction and JRadioButtonMenuItem

I can use the Action putValue(...) method to set the text, icon, mneumonic, accel., etc for my JRadioButtonMenuItem. I can also call setEnabled(...).
Is there a way to use Action to control the state (selected or not-selected) of a JRadioButton or JRadioButtonMenuItem?

No, Action doesn't support a "selected" property yet (it will be added, along with a "large-icon" property, in the 1.5 release). In the meantime, the source code for this article contains a workaround you might be able to use.

Similar Messages

  • AbstractAction and JCheckBox

    Hello,
    I'm using AbstractAction throughout my application, so that I can assign the same action to different components (menu, normal buttons etc.).
    Now I want to create a customized AbstractAction which also handles the selected state of JCheckBox, JMenuItemCheckBox, so that if one CheckBox is selected all CheckBoxes using the same Action is also selected. I thought of using AbstractAction.firePropertyChange, but I am not sure what property to use, and if it will work at all. I want to avoid an infinite recursion.
    Any suggestions?

    Take a look at JGoodies Binding library. Don't reinvent the wheel!!

  • JMenu,JMenuItems and JRadioButtonMenuItem

    Hi I have a JMenu in the JMenuBar.I have a JMenu in it and Then I have 6 JMenuItems which are Of the JRadioButtonMenuItems.
    I need to get on of it selected manually .Can somebody help me in this.I am able to get the name if the MenuItems but I am not able to get it selected.
    Thanks in advance.

    Read this section from the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]Using Menus for an example.

  • Actions and mnemonic keys

    Hi all
    I have a JToolBar with some Actions (classes that extend AbstractAction) and I would like to associate shortcut keys to those Actions, something like ctrl + n to open a new window. How can I do that? Any pointers or ideas would be welcome.

    For selection guidelines see the section Mnemonics which is referenced from Java look and feel Graphics Repository.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ActionMnemonics
        private JToolBar getToolBar()
            JToolBar toolBar = new JToolBar(JToolBar.HORIZONTAL);
            toolBar.add(one);
            JButton button = toolBar.add(two);
            button.setMnemonic(KeyEvent.VK_T);
            return toolBar;
        private Action one = new AbstractAction("one")
                putValue(Action.MNEMONIC_KEY, KeyEvent.VK_O);
            public void actionPerformed(ActionEvent e)
                System.out.println(getValue(Action.NAME));
        private Action two = new AbstractAction("two")
            public void actionPerformed(ActionEvent e)
                System.out.println(getValue(Action.NAME));
        public static void main(String[] args)
            ActionMnemonics test = new ActionMnemonics();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(test.getToolBar(), "North");
            f.setSize(300,200);
            f.setLocation(200,200);
            f.setVisible(true);
    }

  • Keybindings for undo/redo buttons.

    I thought I knew how to do this, and I do seem to have this working fine for cut/copy/paste/select all keybindings CTRL X/C/V/A respectively.
    However I tried to do this for CTRL X and Y undo/redo and it's not working as I intended. Can anyone see what I'm doing wrong?
    I created a SSCCE based off the original example I was following from: [http://www.java2s.com/Code/Java/Swing-JFC/Undoredotextarea.htm]
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.KeyStroke;
    import javax.swing.event.UndoableEditEvent;
    import javax.swing.event.UndoableEditListener;
    import javax.swing.undo.CannotRedoException;
    import javax.swing.undo.UndoManager;
    public class UndoRedoTextArea extends JFrame implements KeyListener{
        private static final long serialVersionUID = 1L;
        protected JTextArea textArea = new JTextArea();
        protected UndoManager undoManager = new UndoManager();
        protected JButton undoButton = new JButton("Undo");
        protected JButton redoButton = new JButton("Redo");
        public UndoRedoTextArea() {
            super("Undo/Redo Demo");
            undoButton.setEnabled(false);
            redoButton.setEnabled(false);
            JPanel buttonPanel = new JPanel(new GridLayout());
            buttonPanel.add(undoButton);
            buttonPanel.add(redoButton);
            JScrollPane scroller = new JScrollPane(textArea);
            getContentPane().add(buttonPanel, BorderLayout.NORTH);
            getContentPane().add(scroller, BorderLayout.CENTER);
            textArea.getDocument().addUndoableEditListener(
                new UndoableEditListener() {
                    public void undoableEditHappened(UndoableEditEvent e) {
                        undoManager.addEdit(e.getEdit());
                        updateButtons();
            undoButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        undoManager.undo();
                    } catch (CannotRedoException cre) {
                        cre.printStackTrace();
                    updateButtons();
            undoButton.addKeyListener(this);
            redoButton.addKeyListener(this);
            redoButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        undoManager.redo();
                    } catch (CannotRedoException cre)  {
                        cre.printStackTrace();
                    updateButtons();
            setSize(400, 300);
            setVisible(true);
        public void updateButtons() {
            undoButton.setText(undoManager.getUndoPresentationName());
            redoButton.setText(undoManager.getRedoPresentationName());
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        public static void main(String argv[]) {
            new UndoRedoTextArea();
        public void keyPressed(KeyEvent e){
            if (e.equals(KeyStroke.getKeyStroke
                (KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK))){
                // undo
                try {
                    undoManager.undo();
                } catch (CannotRedoException cre)  {
                    cre.printStackTrace();
                updateButtons();
            else if (e.equals(KeyStroke.getKeyStroke
                    (KeyEvent.VK_Y, InputEvent.CTRL_DOWN_MASK))){
                // redo
                try  {
                    undoManager.redo();
                } catch (CannotRedoException cre) {
                    cre.printStackTrace();
                updateButtons();
        public void keyTyped(KeyEvent e){}
        public void keyReleased(KeyEvent e){}
    }Edited by: G-Unit on Oct 24, 2010 5:30 AM

    camickr wrote:
    So the way I posted in the second lump of code OK (3rd post) or did you mean something different? Why did you set the key bindings? Did I not state they would be created automatically? I think you need to reread my suggestion (and the tutorial).Because I don't get it, it says only Menu items can contain accelerators and buttons only get mnemonics. I'm not using menu items here, I only have a text pane and 2 buttons. So I set the actions for the InputMap in TextPane. For the buttons, I pretty much used the small bit of code using undoManager.
    I tried to set KEYSTROKE constructor for the action and simply add them to the buttons that way, but this didn't seem to have any response.
    Also I don't get how this could happen anyway if the TextPane has the focus.
    Not like the example using MNEMONICS.
        Action leftAction = new LeftAction(); //LeftAction code is shown later
        button = new JButton(leftAction)
        menuItem = new JMenuItem(leftAction);
    To create an Action object, you generally create a subclass of AbstractAction and then instantiate it. In your subclass, you must implement the actionPerformed method to react appropriately when the action event occurs. Here's an example of creating and instantiating an AbstractAction subclass:
        leftAction = new LeftAction("Go left", anIcon,
                     "This is the left button.",
                     new Integer(KeyEvent.VK_L));
        class LeftAction extends AbstractAction {
            public LeftAction(String text, ImageIcon icon,
                              String desc, Integer mnemonic) {
                super(text, icon);
                putValue(SHORT_DESCRIPTION, desc);
                putValue(MNEMONIC_KEY, mnemonic);
            public void actionPerformed(ActionEvent e) {
                displayResult("Action for first button/menu item", e);
        }This is what I attempted. No errors... It just doesn't work.
    public JPanel p()
        undoButton.addActionListener(new UndoAction(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK)));
        panel.add(undoButton);
        return panel;
    private class UndoAction extends AbstractAction
         public UndoAction(KeyStroke keyStroke)
              putValue(ACCELERATOR_KEY, keyStroke);
         private static final long serialVersionUID = 1L;
         public void actionPerformed(ActionEvent e)
              try
                   if (undoManager.canUndo())
                        undoManager.undo();
              catch (CannotRedoException cre)
                   cre.printStackTrace();
              updateButtons();
    }Edited by: G-Unit on Oct 25, 2010 8:32 AM

  • What is an event handler..?

    I'm trying to learn how to make responsiveness UI. I've read that I can not use SwingUtilities.invokeLater() method if I am in a event handler. The question can seems stupid but I'm only a beginner: what is a event handler? From what I know it might be the actionPerformed method..is it right? Could somebody give me an example? thanks!

    Basically an event handler is a class that performs code.
    It can be any class (even the same that fires the event), but it has to implement the proper interface for the event you want to catch. If you want to perform special code when someone clicks on a button you want to catch an Action, therefor you need an ActionListener, a class that either implements the ActionListener interface (and therefor the method actionPerformed) or your class has to extend AbstractAction (and therefor has an actionPerformed, too).
    It you want to perform special code when someone chooses an element from a list, you want to be informed about a ListSelectionEvent and therefor need a class that implements the ListSelectionListener Interface (and provides the method selectionChanged).
    The class that should react on the event has to be declared as being a listener to the object that fires the events. So an actionListener on a Button would be added by
    button.addActionListener(listener);or
    button.setAction(action);(Note that all variables used are just for clarifiing the type you need and have to be exchanged by the names of your declared objects)
    There are many more events ... really, read the tutorial!

  • Hierarchy advice, please?

    Hi everybody,
    I'm writing a piece of software with a lot of different classes, and in order to organize them I'm trying to place them in a hierarchy. I've had quite a bit of success doing that with windows, but I think for actions I might have strayed from my plan.
    My initial plan was to have a single base class that extended AbstractAction, and have that be the root for all my actions. At the moment, I have that partially implemented; some of my actions do this. I have a lot of other classes, though, in which there are anonymous action listeners and some listeners saved as data members.
    So, my question is this:
    Is it worth it to go back through all these other classes and place all the anonymous listeners in the hierarchy, or is it a better idea to just leave things the way they are? I suspect that the hierarchy approach will make for easier maintainability in the future, but it will be a good chunk of work.
    If anyone could give me opinions on this, I'd appreciate it.
    Thanks,
    Jezzica85

    jezzica85 wrote:
    My initial plan was to have a single base class that extended AbstractAction, and have that be the root for all my actions. At the moment, I have that partially implemented; some of my actions do this. I have a lot of other classes, though, in which there are anonymous action listeners and some listeners saved as data members.Classes called 'AbstractSomething' are usually used to implement an interface called 'Something', which is what your clients should use. All I can suggest is that you consider what your 'Action' interface needs to provide; and think along the lines of an 80-90% solution (or everything you can think of at the moment), rather than a catch-all. If you do miss something out, you can always extend the interface later on for the cases you find it useful.
    Most of the Java collections framework has been set up this way.
    Winston

  • Trapping CTRL + C in my java application

    Hi,
    Is there a way to trap CTRL + C in my running java application ?
    Pls. suggest.
    Awaiting ur replies soon.
    Regards n many thanks

    Hi,
    probably you want a copy-menu item or toolbar button or both.
    I suggest to implement an action (eg. by extending AbstractAction and defined the actionPerformed-method).
    You can then do something like this:
    action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control X"));Setting the action to your menuitem or toolbar button will do the rest.
    If your looking for icons have a look at the Java Look and Feel Graphics Repository:
    http://developer.java.sun.com/developer/techDocs/hi/repository/
    You can add an icon eg. with:
    action.putValue(Action.SMALL_ICON, new ImageIcon((YourClass.class).getResource("/toolbarButtonGraphics/general/Copy16.gif")));and a tooltip:
    action.putValue(Action.SHORT_DESCRIPTION, "Copy");For the standards have a look at:
    http://developer.java.sun.com/developer/techDocs/hi/repository/
    and
    http://java.sun.com/products/jlf/ed2/book/index.html
    eg. Appendix A, B and C
    - Puce

  • How to change the name of an action

    I have defined a AbstractAction and I am wanting to change the name of the action. How can I do this. setName(String name) does not work either. This is what I am doing.
    private class BrowseButtonAction extends AbstractAction
          public BrowseButtonAction(  )
             super("Browse");
           * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
          public void actionPerformed( ActionEvent evt )
             JFileChooser fch = new JFileChooser();
             if ( evt.getSource(  ) == btnBrowseLogo ) {
                //don't change name b/c it's already correct
             } else if ( evt.getSource(  ) == btnBrowseDirectory ) {
                 //set name of action to "BrowseDirectory"
             }else if(evt.getSource() == btnLoadFile){
                //set name of action to "Load";
    }I am assigning this action as follows:
    JButton btnBrowseDirectory  = new JButton(new BrowseButtonAction());
    JButton btnLoad = new JButton(new BrowseButtonAction());
    JButton btnBrowseLogo = new JButton(new BrowseButtonAction());

    Make a BrowseButtonAction constructor that takes a String. Then, pass that String to super instead of always passing "Browse".

  • Multiple components addKeyListener

    When the JFrame with ***lot*** of components on it is active, trying to listen for KeyEvents, i should add a keyListener to every component that is able to have focus.
    Is it possible to add a listener to ALL components, not for every of them? Is there another solution?
    Thanks!

    Hi,
    it depends on how the components are supposed to react
    to the event.
    I once had a similar situation
    I made the container of my components be the listener :
        int condition;
        condition = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
        getInputMap(condition).put(/*a key stroke*/, eventStringId);
        getActionMap().put(eventStringId, new KeyAction(eventStringId));where KeyAction extends AbstractAction
    and I was then performing the action on the focused component.
    but there may be other ways.
    regards,

  • Menus, Buttons and AbstractAction

    I am using the code below to create both a JMenuBar and JToolBar.
    When I clcik on the Menu item "Cut", the println shows cmd: Cut, which is the value from NAME.
    When I click on the ToolBar button, the println shows cmd: null. WHY?
    Have I failed to do something to enable the event to show Cut?
    Could there be a problem in the manner in which I create the JToolBar that initializes the NAME varibale to null?
    The SHORT_DESCRIPTION works and the SMALL_ICON is displayed properly for the button.
    private Action m_cut = new AbstractAction() {
    {     putValue(NAME, "Cut");
         Icon icon = new ImageIcon(getClass().getResource("pics/Cut24.gif"));
         putValue(SMALL_ICON, icon);
         putValue(SHORT_DESCRIPTION, "Cut selected object");
         putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_U));
         putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(
         KeyEvent.VK_X,InputEvent.CTRL_DOWN_MASK));
         public void actionPerformed(ActionEvent evt) {
         System.out.println("example: " + evt.paramString());

    Ok, learned a valuable lesson here. As a newbie, I should not have given up so easily, I only spent an hour trying to figure this out.
    I just went back and played with ActionDemo from the Tutorial and it has the same result as I got, cmd: null, when you press a button.
    So, this appears to be expected behaviour.

  • AbstractAction with accelerators, mnemonics, tooltips, and action commands

    Dear all
    I am writing a new Java app and have successfully made separate buttons and menu items work with the above mentioned features. However, I can see the benefits of using AbstractAction derivatives for all my actions. I have tried to implement this with some success, but, after having read about 70 newsgroup discussions, I still cannot get everything to work.
    private class ProjectOpenAction extends AbstractAction
    ProjectOpenAction(String title, ImageIcon icon)
    super(title, icon);
    putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
    putValue(Action.SHORT_DESCRIPTION, "Open project");
    putValue(Action.ACTION_COMMAND_KEY, "Open an existing Flownet project");
    putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, 0)); // here I actually need Ctrl-O!
    public void actionPerformed(ActionEvent event)
    openProject();
    The mnemonic works, and the tooltips show up. However, I cannot get the accelerators to work at all.
    Furthermore, before I used AbstractActions, I added the same ChangeListener to each button as well as menu item (what a waste) to get to the stateChanged() method. From there I passed the result of getActionCommand() on to my statusbar. I suppose I could make the statusbar a listener of the buttons and menu items too. However, it seems to me that AbstractActions only have PropertyChangeListeners. Will this also trap rollovers on the buttons and menu items?
    Thanks
    Hannes

    Ok, here are couple problems:
    Sun's spec say that key event only works on focus component. How would these events get delivered on the component? You can say that it's not keyevent, but action event. Well, it's started out as key event though. How does Sun trap them and convert them to the Action Event?
    The problem I have is that I would like to put some accelerators on my panel (without any menu). However, only when the panel get focus is when then events got delivered.
    Because of that, I wonder how the menu and Alt-Key works on buttons while they're not a current focused item?
    How else could I do to get this to work? Like key map or something?
    Example:
    A menuless window with 3 buttons. If I press A, it would do 1 things, B would do another, and C would do something else. Use nemmonic, I can get Alt-A, Alt-B, Alt-C to work even they are not focused (the buttons). Ok, how do I just get the A, B, C to work even when they are not focused?
    Thanks all.
    Deudeu wrote:
    Use :
    putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK ));
    Hope this helps,
    Denis

  • JFrame DefaultCloseOperation and AbstractAction

    Hello everybody,
    Here's my problem:
    I have a JFrame and I want to perform some specific operation on closing the frame when user clicks the X button.
    I have created an Action object extending AbstractAction that performs the requested operations. I use this action in the menus.
    How can I mix my Action with the defaultCloseOperation ?
    Thanks !!

    I'm not sure about mixing it with the default close operations, but I have wanted to display things on close, and the easiest way I find to do this is simply add a window listener to the frame, then when the close button is clicked, the "windowClosing(WindowEvent e1)" is called, and you can place your action in there

  • Detect Control-Plus and Control-Minus

    Hi,
    I want to detect keyboard events in a swing application, with the Control key and the '+' or '-' keys pressed (the ones from the keyboard, not from the numpad).
    This is to provide similar behaviour than Firefox for increasing and decreasing the font size.
    I have an English keyboard, in which + is with = key, to be pressed with shift, and - can be pressed directly, without shift.
    I've tried many ways to achieve this behaviour, but have not succeeded yet.
    Platform is Java SE 1.6.0_07 on Red Hat Enterprise Linux 4 with Gnome.
    import static java.awt.event.InputEvent.*;
    import static java.awt.event.KeyEvent.*;
    import static javax.swing.KeyStroke.getKeyStroke;
    // Within some method in some class...
    KeyStroke ctrlPlus, ctrlMinus;
    // Menu items seem correct, but none of the combinations work for me
    ctrlPlus  = getKeyStroke(Character.valueOf('+'), CTRL_DOWN_MASK); // menu item shows Ctrl-+
    ctrlMinus = getKeyStroke(Character.valueOf('-'), CTRL_DOWN_MASK); // menu item shows Ctrl--
    // Menu items seem a bit strange; Ctrl - works, but Ctrl + doesn't
    ctrlPlus  = getKeyStroke(VK_PLUS , CTRL_DOWN_MASK); // menu item shows Ctrl-Plus
    ctrlMinus = getKeyStroke(VK_MINUS, CTRL_DOWN_MASK); // menu item shows Ctrl-Minus
    // None of these combinations work
    ctrlPlus  = getKeyStroke("control +"); // menu item shows nothing
    ctrlMinus = getKeyStroke("control -"); // menu item shows nothingIt seems I can get the desired behaviour with '+' and '-' of the numpad, but:
    1. They are more weird than the normal '+' and '-' keys, which are the ones used by Firefox
    2. The menu items show Ctrl-Numpad + and Ctrl-Numpad - as shortcuts, which are weird also
    3. Not all keyboards have a numpad.
    A solution would be very much appreciated... as well as rewarded with the dukes.

    KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, KeyEvent.SHIFT_DOWN_MASK | KeyEvent.CTRL_DOWN_MASK)This works indeed with CTRL_DOWN_MASK alone (not tested with the other mask), thanks.
    However, this solution has two drawbacks:
    1. The accelerator string is shown as Ctrl-=, while I want Ctrl-+ to be shown
    2. '+' key may not coincide with '=' in non-English keyboards (e.g. it doesn't coincide in Spanish keyboards)
    I've found a solution that required a bit more work:
    1. Create the actions with the keyStroke you want to be shown (in my case, Ctrl-- and Ctrl-+):
    ctrlPlus  = getKeyStroke("ctrl typed +");  // Ctrl-+ is shown
    ctrlMinus = getKeyStroke("ctrl typed -");  // Ctrl-- is shown
    Action actionPlus = new AbstractAction() { ... };
    actionPlus.setAccelerator(ctrlPlus);
    Action actionMinus = new AbstractAction() { ... };
    actionMinus.setAccelerator(ctrlMinus);2. Bind the keys you actually want to the corresponding action:
    JComponent window = ...;  // root window
    InputMap inputMap = window.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = window.getActionMap();
    Object actionMapKeyPlus  = "ctrl+";
    Object actionMapKeyMinus = "ctrl-";
    inputMap.put(getKeyStroke(VK_EQUALS  , CTRL_DOWN_MASK), actionMapKeyPlus);  // + key in English keyboards
    inputMap.put(getKeyStroke(VK_PLUS    , CTRL_DOWN_MASK), actionMapKeyPlus);  // + key in non-English keyboards
    inputMap.put(getKeyStroke(VK_ADD     , CTRL_DOWN_MASK), actionMapKeyPlus);  // + key on the numpad
    inputMap.put(getKeyStroke(VK_MINUS   , CTRL_DOWN_MASK), actionMapKeyMinus); // - key
    inputMap.put(getKeyStroke(VK_SUBTRACT, CTRL_DOWN_MASK), actionMapKeyMinus); // - key on the numpad
    actionMap.put(actionMapKeyPlus, actionPlus);
    actionMap.put(actionMapKeyMinus, actionMinus);More complicated than expected, but at least works.
    Thanks for the help.
    God bless,
    Jaime

  • HelpSet.findHelpSet() returns null, and trapping ID errors

    I was having a problem initializing JavaHelp. HelpSet.findHelpSet() was returning null. I searched the forum, and found it was a common problem, but the answers were unhelpful. The answers pointed to a problem with CLASSPATH, but offered little in the way of advice for a newbie like myself on how to deal with it.
    A second issue concerns HelpBroker.enableHelpOnButton(). If you feed it a bogus ID, it throws an exception, and there's no way to trap it and fail gracefully. JHUG doesn't provide much in the way of alternatives.
    Now, having done a bit of research and testing, I'm willing to share a cookbook formula for what worked for me.
    I'm working in a project directory that contains MyApp.jar and the Help subdirectory, including Help/Help.hs. My first step is to copy jh.jar to the project directory.
    Next, in the manifest file used to generate MyApp.jar, I add the line:
        Class-Path: jh.jar Help/I'm working with Eclipse, so in Eclipse, I use Project - Properties - Java Build Path - Libraries to add JAR file jh.jar, and Class Folder Tony/Help
    I define the following convenience class:
    public class HelpAction extends AbstractAction
        private static HelpBroker helpBroker = null;
        private String label = null;
        public HelpAction( String name, String label )
            super( name );
            this.label = label;
        public void actionPerformed( ActionEvent event )
            displayHelp( label );
        public static boolean displayHelp( String label )
            if ( helpBroker == null )
                Utils.reportError( "Help package not initialized!" );
                return false;
            try
                helpBroker.setCurrentID( label );
                helpBroker.setDisplayed( true );
                return true;
            catch ( Exception e )
                Utils.reportError( e, "Help for " + label + " not found" );
                return false;
        public static boolean initialize( String hsName )
            URL hsURL = HelpSet.findHelpSet( null, hsName );
            if ( hsURL == null )
                Utils.reportError( "Can't find helpset " + hsName );
                return false;
            try
                HelpSet helpSet = new HelpSet( null, hsURL );
                helpBroker = helpSet.createHelpBroker();
            catch ( HelpSetException e )
                Utils.reportError( e, "Can't open helpset " + hsName );
                return false;
            return true;
    }If you use this class in your own code, you'll want to replace Utils.reportError() with something of your own devising.
    Finally, in my GUI class, I use the following:
        JPanel panel = ...
        JMenu menu = ...
        JToolbar toolbar = ...
        HelpAction.initialize( "Help.hs" )
        Action gsAction = new HelpAction( "Getting Started Guide", "gs.top" );
        menu.add( gsAction );
        JButton helpButton = new HelpAction( "Help", "man.top" );
        toolbar.add( helpButton );
        InputMap imap = panel.getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
        imap.put( KeyStroke.getKeyStroke( "F1" ), "F1help" );
        ActionMap amap = panel.getActionMap();
        amap.put( "F1help", new HelpAction( null, "man.top" ) );

    Sorry, the sixth-from-last line of my example should read,
        JButton helpButton = new JButton( new HelpAction( "Help", "man.top" ) );

Maybe you are looking for

  • Imported MPEG-4 file into Imovie 09 no picture only sound

    Imported a MPEG-4 file taken from a Samsung HD video, into IMovie (5.0.2), sound plays but no picture

  • Saving MS Word document in HTML and importing

    The Word doc is over 4MB with linked TOC, text, and text boxes filled with text from mainframe applications. The text boxes are difficult to control - non-symetrical and, in some instances, overlapping. The text boxes are Fireworks gifs housed in a s

  • JSF problems with Javascript

    Hi everyone!! The situation is this: I have a datable with one of its columns make an h:commanLink, which has two f:params, its actionListener is a function of a ManagedBean. This is JSF, not MyFaces. In IE, When the link is pressed, it shows a javas

  • DOWNLOADING ONTO IPHONE PREVIOUSLY DOWNLOADED MUSIC.

    Hi, I have downloaded 2 albums onto my iphone over the last couple of weeks. When i have connected my phone to itunes and synced the music these albums have disappeared from my phone but remain on my computer in itunes music and library. They are als

  • Can't connect to a some sites

    since a couple of days I can not reach some sites. examples are: http://www.brushesapp.com/ http://tweepsapp.com/ all internet connections are just fine, there are just a very few sites i can't reach. but i can reach them with gprs on my iphone so i