How do I add a toggle-able action to the toolbar/main menu?

Apache NetBeans Wiki Index

Note: These pages are being reviewed.

  • extend from org.openide.util.actions.BooleanStateAction

  • in the constructor add a property-change listener to the action itself and let the action implement `PropertyChangeListener `

  • within PropertyChangeListener#propertyChange check for the propertyName PROP_BOOLEAN_STATE to distinguish the toggle event from other events


package de.markiewb.netbeans.plugins.debuggerutils;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.Action;
import org.netbeans.api.annotations.common.StaticResource;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.*;
import org.openide.util.NbBundle.Messages;
import org.openide.util.actions.BooleanStateAction;

        category = "Debug",
        id = "de.markiewb.netbeans.plugins.debuggerutils.SkipAllBreakpoints"
        lazy = false,
        displayName = "#CTL_SkipAllBreakpoints"
    @ActionReference(path = "Toolbars/Debug", position = 1050),
    @ActionReference(path = "Menu/RunProject", position = 2350)
@Messages("CTL_SkipAllBreakpoints=Skip all breakpoin&ts")

public final class SkipAllBreakpoints extends BooleanStateAction implements PropertyChangeListener {

    private static final String iconpath = "de/markiewb/netbeans/plugins/debuggerutils/Breakpoint_stroke.png";

    public SkipAllBreakpoints() {

        setBooleanState(false); //initially unchecked

    public void propertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName().equals(PROP_BOOLEAN_STATE)) {
            /* your action here, get the state by getBooleanState()*/

    public HelpCtx getHelpCtx() {
        return HelpCtx.DEFAULT_HELP;

    public String getName() {
        return Bundle.CTL_SkipAllBreakpoints();

    protected String iconResource() {
        return iconpath;