GitHub user stefanofornari created a discussion: Custom Action not picking the icon nor shortcut in menus
### Apache NetBeans version Apache NetBeans 27 ### What happened As per all documentation I have found and in particular [How do i add an icon to the context menu](https://netbeans.apache.org/wiki/main/netbeansdevelopperfaq/DevFaqAddIconToContextMenu/), The following action should show in the project context menu the icon and the shortcut. None are actually displayed as per the screenshot. ```java @ActionID( category = "Edit", id = "com.example.SomeAction" ) @ActionRegistration( iconBase = "icons/restart.png", displayName = "#CTL_SomeAction", lazy = true ) @ActionReferences({ @ActionReference(path = "Shortcuts", name = "DOS-K"), @ActionReference(path = "Projects/Actions", position = 100), }) @Messages("CTL_SomeAction=Some Action") public final class SomeAction extends AbstractAction implements ActionListener, Presenter.Popup { @StaticResource private static final String ICON = "icons/restart.png"; private static final long serialVersionUID = 1L; private final LookupListener lookupListener; private final Lookup.Result<Project> result; public SomeAction() { putValue(SMALL_ICON, ImageUtilities.loadImageIcon(ICON, false)); putValue(NAME, Bundle.CTL_SomeAction()); putValue("iconBase", ICON); result = Utilities.actionsGlobalContext().lookupResult(Project.class); this.lookupListener = new LookupListener() { @Override public void resultChanged(LookupEvent ev) { EventQueue.invokeLater(new Runnable() { @Override public void run() { setEnabled(!result.allInstances().isEmpty()); } }); } }; result.addLookupListener(WeakListeners.create(LookupListener.class, this.lookupListener, result)); this.lookupListener.resultChanged(null); } @Override public void actionPerformed(ActionEvent e) { Logger.getLogger("com.example").info("actionPerformed"); Action action = FileUtil.getConfigObject("Actions/Edit/com-example-SomeAction.instance", Action.class); KeyStroke ks = action != null ? (KeyStroke) action.getValue(Action.ACCELERATOR_KEY) : null; javax.swing.JOptionPane.showMessageDialog(null, "Hello! " + ks); } @Override public JMenuItem getPopupPresenter() { Logger.getLogger("com.example").info("getPopupPresenter"); return new JMenuItem(this); } } ``` <img width="1080" height="1440" alt="Image" src="https://github.com/user-attachments/assets/2573e511-70dd-4a15-95e6-8e59d533775b" /> ### Language / Project Type / NetBeans Component NetBeans Platform ### How to reproduce use the code above. I have attached a simple project too. [action.zip](https://github.com/user-attachments/files/21985819/action.zip) ### Did this work correctly in an earlier version? No / Don't know ### Operating System Linux Ubuntu ### JDK any ### Apache NetBeans packaging Apache NetBeans binary zip ### Anything else I can help debugging provided some directions ### Are you willing to submit a pull request? Yes GitHub link: https://github.com/apache/netbeans/discussions/8767 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
