Example usage for javax.swing Action setEnabled

List of usage examples for javax.swing Action setEnabled

Introduction

In this page you can find the example usage for javax.swing Action setEnabled.

Prototype

public void setEnabled(boolean b);

Source Link

Document

Sets the enabled state of the Action .

Usage

From source file:Main.java

public static void main(String[] args) {
    JFileChooser chooser = new JFileChooser();

    BasicFileChooserUI ui = (BasicFileChooserUI) chooser.getUI();
    Action folder = ui.getNewFolderAction();
    folder.setEnabled(false);

    chooser.showSaveDialog(null);/*  ww  w.j av a2  s .  c o m*/
}

From source file:PrintHelloAction.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Action Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final Action printAction = new PrintHelloAction();
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menuBar.add(menu);//from w  w  w . j  a  v a2 s  .  co m
    menu.add(new JMenuItem(printAction));
    JToolBar toolbar = new JToolBar();
    toolbar.add(new JButton(printAction));
    JButton enableButton = new JButton("Enable");
    ActionListener enableActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            printAction.setEnabled(true);
        }
    };
    enableButton.addActionListener(enableActionListener);
    JButton disableButton = new JButton("Disable");
    ActionListener disableActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            printAction.setEnabled(false);
        }
    };
    disableButton.addActionListener(disableActionListener);
    JButton relabelButton = new JButton("Relabel");
    ActionListener relabelActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            printAction.putValue(Action.NAME, "Changed Action Value");
        }
    };
    relabelButton.addActionListener(relabelActionListener);
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(enableButton);
    buttonPanel.add(disableButton);
    buttonPanel.add(relabelButton);
    frame.setJMenuBar(menuBar);
    frame.add(toolbar, BorderLayout.SOUTH);
    frame.add(buttonPanel, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Action Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final Action printAction = new PrintHelloAction();

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    menuBar.add(menu);/*from   w ww  .  ja  va  2  s. c o  m*/
    menu.add(new JMenuItem(printAction));

    JToolBar toolbar = new JToolBar();
    toolbar.add(new JButton(printAction));

    JButton enableButton = new JButton("Enable");
    ActionListener enableActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            printAction.setEnabled(true);
        }
    };
    enableButton.addActionListener(enableActionListener);

    JButton disableButton = new JButton("Disable");
    ActionListener disableActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            printAction.setEnabled(false);
        }
    };
    disableButton.addActionListener(disableActionListener);

    JButton relabelButton = new JButton("Relabel");
    ActionListener relabelActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            printAction.putValue(Action.NAME, "Hello, World");
        }
    };
    relabelButton.addActionListener(relabelActionListener);

    JPanel buttonPanel = new JPanel();
    buttonPanel.add(enableButton);
    buttonPanel.add(disableButton);
    buttonPanel.add(relabelButton);

    frame.setJMenuBar(menuBar);

    frame.add(toolbar, BorderLayout.SOUTH);
    frame.add(buttonPanel, BorderLayout.NORTH);
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    Container pane = f.getContentPane();
    Icon icon = new RedOvalIcon();
    final Action action = new MyAction("Hello", icon);
    // Add tooltip
    action.putValue(Action.SHORT_DESCRIPTION, "World");
    JToolBar jt1 = new JToolBar();
    JButton b1 = new JButton(action);
    jt1.add(b1);//from w  ww.j a  v  a  2  s.  com
    pane.add(jt1, BorderLayout.NORTH);
    JToolBar jt2 = new JToolBar();
    JButton b2 = new JButton(action);
    jt2.add(b2);
    pane.add(jt2, BorderLayout.SOUTH);
    JButton jb = new JButton("Toggle Action");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            action.setEnabled(!action.isEnabled());
        }
    });
    pane.add(jb, BorderLayout.CENTER);
    f.setSize(200, 200);
    f.show();
}

From source file:Main.java

public static void refleshAction(JComponent com, KeyStroke keyStroke) {
    InputMap im = com.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    Object o = im.get(keyStroke);
    if (o == null) {
        im = com.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        o = im.get(keyStroke);/*from   w  w  w.ja v  a  2  s  .c  om*/
    }
    if (o != null) {
        Action a = com.getActionMap().get(o);
        a.setEnabled(a.isEnabled());
    }
}

From source file:com.employee.scheduler.common.swingui.SolverAndPersistenceFrame.java

private void setSolvingState(boolean solving) {
    for (Action action : quickOpenUnsolvedActionList) {
        action.setEnabled(!solving);
    }// ww  w. j av a  2  s  .co m
    for (Action action : quickOpenSolvedActionList) {
        action.setEnabled(!solving);
    }
    importAction.setEnabled(!solving && solutionBusiness.hasImporter());
    openAction.setEnabled(!solving);
    saveAction.setEnabled(!solving);
    exportAction.setEnabled(!solving && solutionBusiness.hasExporter());
    solveAction.setEnabled(!solving);
    solveButton.setVisible(!solving);
    terminateSolvingEarlyAction.setEnabled(solving);
    terminateSolvingEarlyButton.setVisible(solving);
    solutionPanel.setEnabled(!solving);
    progressBar.setIndeterminate(solving);
    progressBar.setStringPainted(solving);
    progressBar.setString(solving ? "Solving..." : null);
    showConstraintMatchesDialogAction.setEnabled(!solving);
    solutionPanel.setSolvingState(solving);
}

From source file:com.nbt.TreeFrame.java

protected void updateActions() {
    Map<Integer, Action> actionMap = new LinkedHashMap<Integer, Action>();
    actionMap.put(NBTConstants.TYPE_BYTE, addByteAction);
    actionMap.put(NBTConstants.TYPE_SHORT, addShortAction);
    actionMap.put(NBTConstants.TYPE_INT, addIntAction);
    actionMap.put(NBTConstants.TYPE_LONG, addLongAction);
    actionMap.put(NBTConstants.TYPE_FLOAT, addFloatAction);
    actionMap.put(NBTConstants.TYPE_DOUBLE, addDoubleAction);
    actionMap.put(NBTConstants.TYPE_BYTE_ARRAY, addByteArrayAction);
    actionMap.put(NBTConstants.TYPE_STRING, addStringAction);
    actionMap.put(NBTConstants.TYPE_LIST, addListAction);
    actionMap.put(NBTConstants.TYPE_COMPOUND, addCompoundAction);
    for (Action action : actionMap.values())
        action.setEnabled(false);

    Action[] actions = { openAction };
    for (Action action : actions)
        action.setEnabled(false);//  w w  w  . j  a  v  a2s .c om

    if (treeTable == null)
        return;

    int row = treeTable.getSelectedRow();
    deleteAction.setEnabled(row > 0);
    if (row == -1)
        return;
    TreePath path = treeTable.getPathForRow(row);
    Object last = path.getLastPathComponent();
    TreePath parentPath = path.getParentPath();
    Object parentLast = parentPath == null ? null : parentPath.getLastPathComponent();

    if (last instanceof ByteArrayTag || parentLast instanceof ByteArrayTag || last instanceof ByteWrapper
            || parentLast instanceof ByteWrapper) {
        addByteAction.setEnabled(true);
    } else if (last instanceof ListTag || parentLast instanceof ListTag) {
        if (!(last instanceof ListTag))
            last = parentLast;

        ListTag list = (ListTag) last;
        @SuppressWarnings("unchecked")
        Class<Tag<?>> c = (Class<Tag<?>>) list.getType();
        int type = NBTUtils.getTypeCode(c);
        Action action = actionMap.get(type);
        action.setEnabled(true);
    } else if (last instanceof CompoundTag || parentLast instanceof CompoundTag || last instanceof TagWrapper
            || parentLast instanceof TagWrapper) {
        for (Action action : actionMap.values())
            action.setEnabled(true);
    } else if (last instanceof Region || last instanceof World || last instanceof NBTFileBranch) {
        openAction.setEnabled(true);
    }
}

From source file:edu.ku.brc.ui.UIRegistry.java

/**
 * @param nameStr//from  w  w  w. j a va 2s.c o  m
 * @param enable
 * @param selected
 */
public static void enableActionAndMenu(final String nameStr, final boolean enable, final Boolean selected) {
    Action action = UIRegistry.getAction(nameStr);
    if (action != null) {
        action.setEnabled(enable);
    }

    Component comp = UIRegistry.get(nameStr);
    if (comp instanceof JCheckBoxMenuItem) {
        ((JCheckBoxMenuItem) comp).setEnabled(enable);
        if (selected != null) {
            ((JCheckBoxMenuItem) comp).setSelected(selected);
        }

    } else if (comp instanceof JMenuItem) {
        ((JMenuItem) comp).setEnabled(enable);
    }
}

From source file:com.diversityarrays.kdxplore.trialmgr.trait.TraitExplorerPanel.java

private JButton initAction(Action action, ImageId imageId, String toolTip, KeyStroke keyStroke) {
    KDClientUtils.initAction(imageId, action, toolTip, false);
    action.setEnabled(false);

    String command = action.toString();

    JButton result = new JButton(action);
    result.getActionMap().put(command, action);
    result.getInputMap(JComponent.WHEN_FOCUSED).put(keyStroke, command);

    return result;
}

From source file:com.intuit.tank.tools.debugger.ActionProducer.java

/**
 * /*from  ww w  .ja v a2 s  .c  om*/
 * @return
 */
public Action getFindAction() {
    Action ret = actionMap.get(ACTION_FIND);
    if (ret == null) {
        ret = new AbstractAction(ACTION_FIND, getIcon("find.png", IconSize.SMALL)) {
            private static final long serialVersionUID = 1L;
            private FindReplaceDialog dialog;

            @Override
            public void actionPerformed(ActionEvent event) {
                try {
                    if (dialog == null) {
                        dialog = new FindReplaceDialog(debuggerFrame, DialogType.SEARCH);
                    }
                    dialog.setVisible(true);
                } catch (HeadlessException e) {
                    showError("Error opening file: " + e);
                }
            }
        };
        ret.putValue(Action.SHORT_DESCRIPTION, "Find in script.");
        ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('F', menuActionMods));
        ret.putValue(Action.MNEMONIC_KEY, new Integer('F'));
        ret.setEnabled(false);
        actionMap.put(ACTION_FIND, ret);
    }
    return ret;
}