Apache NetBeans Wiki Index

Note: These pages are being reviewed.

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

  • 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;

Apache Migration Information

The content in this page was kindly donated by Oracle Corp. to the Apache Software Foundation.

This page was exported from http://wiki.netbeans.org/DevFaqToggleActionAddToEditorToolbar , that was last modified by NetBeans user Markiewb on 2016-06-02T21:50:34Z.

NOTE: This document was automatically converted to the AsciiDoc format on 2018-02-07, and needs to be reviewed.