Re: How to Add tooltip to action registered using @ActionRegistration

Peter Hansson <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <CAC55jYM=h0W2OTZRF8Z=kNeZ1Nn9m399sjPvpPhRS2UJetqcfg@mail.gmail.com>
Instead of what you are doing then extend AbstractAction and use
Action.SHORT_DESCRIPTION.

Here's an example:

@ActionID(
        category = "Edit",
        id = "org.test.SomeAction"
)
@ActionRegistration(
        displayName = "#CTL_SomeAction"
)
@ActionReference(path = "Menu/File", position = 1300)
@Messages({
       "CTL_SomeAction=Some Action",
       "CTL_SomeActionTooltip=My tooltip text"
})
public final class SomeAction extends AbstractAction implements
ActionListener {

    // Remember constructor must be no-arg
    public SomeAction() {
        putValue(Action.SHORT_DESCRIPTION, CTL_SomeActionTooltip());
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO implement action body
    }
}

I believe that should do it. Haven't actually tested it.  :-)

Regards,

Peter

PS: The NetBeans Wizard in the IDE should in my mind be changed to be based
on code that extends AbstractAction as this is more flexible. Just my two
cents. Haven't thought too much about it though. Maybe such a change will
have adverse effects for some ?



On Wed, Aug 17, 2016 at 12:26 AM, Todd Stevenson <[email protected]>
wrote:

> I used the Netbeans wizard to create an action to use in my editor pane,
> but cannot see how to set a tooltip for this action.  I can see that all
> the other actions in the editor pane have tooltips.  How can I set the
> tooltip:
>
>
>
> /*
>
> * To change this license header, choose License Headers in Project
> Properties.
>
> * To change this template file, choose Tools | Templates
>
> * and open the template in the editor.
>
> */
>
> package org.ihc.cem.ceml.cedar.modules.editor.actions;
>
>
>
> import java.awt.event.ActionEvent;
>
> import java.awt.event.ActionListener;
>
> import org.openide.awt.ActionID;
>
> import org.openide.awt.ActionReference;
>
> import org.openide.awt.ActionReferences;
>
> import org.openide.awt.ActionRegistration;
>
> import org.openide.cookies.EditorCookie;
>
> import org.openide.util.NbBundle;
>
>
>
> /**
>
> *
>
> * @author dtsteven
>
> */
>
> @ActionID(
>
>         category = "Edit",
>
>         id = "org.ihc.cem.ceml.cedar.modules.editor.actions.
> CompileWithTerminology"
>
> )
>
> @ActionRegistration(
>
>         iconBase = "org/ihc/cem/ceml/cedar/modules/editor/resources/
> compileAll.gif",
>
>         displayName = "#CTL_CompileWithTerminology"
>
> )
>
> @ActionReferences({
>
>     @ActionReference(path = "Editors/text/x-cem/Toolbars/Default",
> position = 4500, separatorBefore = 4490)
>
> })
>
> @NbBundle.Messages("CTL_CompileWithTerminology=Compile with Terminology
> Validation")
>
> public final class CompileWithTerminology implements ActionListener {
>
>
>
>     private final EditorCookie context;
>
>
>
>     public CompileWithTerminology(EditorCookie context) {
>
>         this.context = context;
>
>     }
>
>
>
>     @Override
>
>     public void actionPerformed(ActionEvent ev) {
>
>
>
>
>
>     }
>
> }
>
>
>
> *Todd Stevenson*
>
> Senior Software Engineer
>
> Data Semantics and Clinical Modeling
>
> *D*ata *a*nd *A*nalytics *S*ervices (DaAS)
>
> *Intermountain Healthcare*
>
> *3930 Parkway Blvd |Salt Lake City, UT 84120*
>
> Office: 801-442-5112 | Cell: 801-589-1115
>
> [email protected]
>
>
>
image003.jpg (image/jpeg, 2.9 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.