Java Code Examples for javax.swing.JToggleButton#setAction()

The following examples show how to use javax.swing.JToggleButton#setAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScenarioEditor.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addTool(final Tool t, JMenu menu, JToolBar toolbar, ButtonGroup menuGroup, ButtonGroup toolbarGroup) {
    final JToggleButton toggle = new JToggleButton();
    final JCheckBoxMenuItem check = new JCheckBoxMenuItem();
    Action action = new AbstractAction(t.getName()) {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (currentTool != null) {
                    currentTool.deactivate();
                }
                currentTool = t;
                toggle.setSelected(true);
                check.setSelected(true);
                currentTool.activate();
            }
        };
    toggle.setAction(action);
    check.setAction(action);
    menu.add(check);
    toolbar.add(toggle);
    menuGroup.add(check);
    toolbarGroup.add(toggle);
}
 
Example 2
Source File: GMLEditor.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void addTool(final Tool t, JMenu menu, JToolBar toolbar, ButtonGroup menuGroup, ButtonGroup toolbarGroup) {
    final JToggleButton toggle = new JToggleButton();
    final JCheckBoxMenuItem check = new JCheckBoxMenuItem();
    Action action = new AbstractAction(t.getName()) {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (currentTool != null) {
                    currentTool.deactivate();
                }
                currentTool = t;
                toggle.setSelected(true);
                check.setSelected(true);
                currentTool.activate();
            }
        };
    toggle.setAction(action);
    check.setAction(action);
    menu.add(check);
    if (toolbar != null) {
        toolbar.add(toggle);
        toolbarGroup.add(toggle);
    }
    menuGroup.add(check);
}
 
Example 3
Source File: ClientGui.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private JScrollPane scroll(final JTextArea text) {
    final JToggleButton toggleButton = new JToggleButton();
    toggleButton.setAction(new AbstractAction() {
        private static final long serialVersionUID = -4214143754637722322L;

        @Override
        public void actionPerformed(final ActionEvent e) {
            final boolean wrap = toggleButton.isSelected();
            text.setLineWrap(wrap);
        }
    });
    toggleButton.setToolTipText("Toggle line wrapping");
    final JScrollPane scrollStatusLog = new JScrollPane(text, //
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, //
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollStatusLog.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, toggleButton);
    return scrollStatusLog;
}
 
Example 4
Source File: ToggleDebuggingAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    toggleButton = new JToggleButton();
    toggleButton.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
    toggleButton.setIcon((Icon) getValue(SMALL_ICON));
    toggleButton.setAction(this); // this will make hard ref to button => check GC
    return toggleButton;
}
 
Example 5
Source File: ActionFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    JToggleButton toggleButton = new JToggleButton();
    toggleButtonRef = new WeakReference<>(toggleButton);
    toggleButton.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
    toggleButton.setIcon((Icon) getValue(SMALL_ICON));
    toggleButton.setAction(this); // this will make hard ref to button => check GC
    return toggleButton;
}
 
Example 6
Source File: ToggleHighlightSearchAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ToggleHighlightSearchAction() {
    super();
    putValue("noIconInMenu", Boolean.TRUE); // NOI18N
    JToggleButton b = new MyGaGaButton();
    b.setModel(new HighlightButtonModel());
    b.setAction(this);
}
 
Example 7
Source File: ToggleHighlightSearchAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getToolbarPresenter() {
    JToggleButton b = new MyGaGaButton();
    b.setModel(new HighlightButtonModel());
    b.putClientProperty("hideActionText", Boolean.TRUE); //NOI18N
    b.setAction(this);
    return b;
}
 
Example 8
Source File: ToolBar.java    From Dayon with GNU General Public License v3.0 5 votes vote down vote up
public void addToggleAction(Action action) {
	final JToggleButton button = new JToggleButton();

	button.setMargin(zeroInsets);
	button.setHideActionText(true);
	button.setAction(action);

	if (action.getValue(Action.SMALL_ICON) == null) {
		button.setText((String) action.getValue("DISPLAY_NAME"));
	}

	button.setFocusable(false);

	add(button);
}
 
Example 9
Source File: SwingSet2.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
		 * Adds the toggle button.
		 *
		 * @param a the a
		 * @return the j toggle button
		 */
		JToggleButton addToggleButton(Action a) {
			JToggleButton tb = new JToggleButton(
					(String)a.getValue(Action.NAME),null
//					(Icon)a.getValue(Action.SMALL_ICON)
			);
//			tb.setMargin(zeroInsets);
//			tb.setText(null);
			tb.setEnabled(a.isEnabled());
			tb.setToolTipText((String)a.getValue(Action.SHORT_DESCRIPTION));
			tb.setAction(a);
			add(tb);
			return tb;
		}