Example usage for javax.swing AbstractButton setEnabled

List of usage examples for javax.swing AbstractButton setEnabled

Introduction

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

Prototype

public void setEnabled(boolean b) 

Source Link

Document

Enables (or disables) the button.

Usage

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JToggleButton("Press Me");
    jb.setEnabled(false);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);/*  w w w . j  a v  a  2  s . co  m*/
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

private static void inactivateOption(Container container, String text) {
    Component[] comps = container.getComponents();
    for (Component comp : comps) {
        if (comp instanceof AbstractButton) {
            AbstractButton btn = (AbstractButton) comp;
            if (btn.getActionCommand().equals(text)) {
                btn.setEnabled(false);
                return;
            }/*from w w w  . j av a 2  s  .  c om*/
        } else if (comp instanceof Container) {
            inactivateOption((Container) comp, text);
        }
    }

}

From source file:com.projity.menu.MenuManager.java

public void setActionEnabled(String id, boolean enable) {
    Collection buttons = toolBarFactory.getButtonsFromId(id);
    if (buttons != null) {
        Iterator i = buttons.iterator();
        while (i.hasNext()) {
            AbstractButton button = (AbstractButton) i.next();
            if (button != null)
                button.setEnabled(enable);
        }/*from w  w w .jav a2s.c  om*/
    }
    JMenuItem menuItem = menuFactory.getMenuItemFromId(id);
    if (menuItem != null)
        menuItem.setEnabled(enable);
}

From source file:org.esa.snap.rcp.statistics.ChartPagePanel.java

private JPanel createTopPanel() {
    refreshButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/ViewRefresh22.png"), false);
    refreshButton.setToolTipText("Refresh View");
    refreshButton.setName("refreshButton");
    refreshButton.addActionListener(e -> {
        updateChartData();/*w  w w  . j a  va 2 s . c  om*/
        refreshButton.setEnabled(false);
    });

    AbstractButton switchToTableButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Table24.png"), false);
    switchToTableButton.setToolTipText("Switch to Table View");
    switchToTableButton.setName("switchToTableButton");
    switchToTableButton.setEnabled(hasAlternativeView());
    switchToTableButton.addActionListener(e -> showAlternativeView());

    final TableLayout tableLayout = new TableLayout(6);
    tableLayout.setColumnFill(2, TableLayout.Fill.HORIZONTAL);
    tableLayout.setColumnWeightX(2, 1.0);
    tableLayout.setRowPadding(0, new Insets(0, 4, 0, 0));
    JPanel buttonPanel = new JPanel(tableLayout);
    buttonPanel.add(refreshButton);
    tableLayout.setRowPadding(0, new Insets(0, 0, 0, 0));
    buttonPanel.add(switchToTableButton);
    buttonPanel.add(new JPanel());

    return buttonPanel;
}

From source file:net.pms.newgui.LooksFrame.java

public JComponent buildContent() {
    JPanel panel = new JPanel(new BorderLayout());
    JToolBar toolBar = new JToolBar();
    toolBar.setFloatable(false);//from w w w. j  av  a  2 s. c  o m
    toolBar.setRollover(true);

    toolBar.add(new JPanel());

    if (PMS.getConfiguration().useWebInterface()) {
        webinterface = createToolBarButton(Messages.getString("LooksFrame.29"), "button-wif.png");
        webinterface.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String error = null;
                if (PMS.get().getWebInterface() != null && isNotBlank(PMS.get().getWebInterface().getUrl())) {
                    try {
                        URI uri = new URI(PMS.get().getWebInterface().getUrl());
                        try {
                            Desktop.getDesktop().browse(uri);
                        } catch (RuntimeException | IOException be) {
                            LOGGER.error("Cound not open the default web browser: {}", be.getMessage());
                            LOGGER.trace("", be);
                            error = Messages.getString("LooksFrame.BrowserError") + "\n" + be.getMessage();
                        }
                    } catch (URISyntaxException se) {
                        LOGGER.error("Could not form a valid web interface URI from \"{}\": {}",
                                PMS.get().getWebInterface().getUrl(), se.getMessage());
                        LOGGER.trace("", se);
                        error = Messages.getString("LooksFrame.URIError");
                    }
                } else {
                    error = Messages.getString("LooksFrame.URIError");
                }
                if (error != null) {
                    JOptionPane.showMessageDialog(null, error, Messages.getString("Dialog.Error"),
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        });
        webinterface.setToolTipText(Messages.getString("LooksFrame.30"));
        webinterface.setEnabled(configuration.useWebInterface());
        toolBar.add(webinterface);
        toolBar.addSeparator(new Dimension(20, 1));
    }

    restartIcon = (AnimatedIcon) reload.getIcon();
    restartRequredIcon.start();
    setReloadable(false);
    reload.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            reload.setEnabled(false);
            PMS.get().reset();
        }
    });
    reload.setToolTipText(Messages.getString("LooksFrame.28"));
    toolBar.add(reload);

    toolBar.addSeparator(new Dimension(20, 1));
    AbstractButton quit = createToolBarButton(Messages.getString("LooksFrame.5"), "button-quit.png");
    quit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            quit();
        }
    });
    toolBar.add(quit);
    if (System.getProperty(START_SERVICE) != null) {
        quit.setEnabled(false);
    }
    toolBar.add(new JPanel());

    // Apply the orientation to the toolbar and all components in it
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    toolBar.applyComponentOrientation(orientation);
    toolBar.setBorder(new EmptyBorder(new Insets(8, 0, 0, 0)));

    panel.add(toolBar, BorderLayout.NORTH);
    panel.add(buildMain(), BorderLayout.CENTER);
    status = new JLabel("");
    status.setBorder(BorderFactory.createEmptyBorder());
    status.setComponentOrientation(orientation);

    // Calling applyComponentOrientation() here would be ideal.
    // Alas it horribly mutilates the layout of several tabs.
    //panel.applyComponentOrientation(orientation);
    panel.add(status, BorderLayout.SOUTH);

    return panel;
}

From source file:org.esa.beam.visat.toolviews.stat.StatisticsPanel.java

private AbstractButton getExportButton() {
    final AbstractButton export = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Export24.gif"),
            false);/*from   w  w w .j av  a  2s . c  om*/
    export.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JPopupMenu viewPopup = new JPopupMenu("Export");
            viewPopup.add(exportAsCsvAction);
            viewPopup.add(putStatisticsIntoVectorDataAction);
            final Rectangle buttonBounds = export.getBounds();
            viewPopup.show(export, 1, buttonBounds.height + 1);
        }
    });
    export.setEnabled(false);
    return export;
}

From source file:org.openscience.jmol.app.Jmol.java

/**
 * Create a button to go inside of the toolbar.  By default this
 * will load an image resource.  The image filename is relative to
 * the classpath (including the '.' directory if its a part of the
 * classpath), and may either be in a JAR file or a separate file.
 *
 * @param key The key in the resource file to serve as the basis
 *  of lookups./* ww  w . j a  v a2  s .  c o  m*/
 * @return Button
 */
protected AbstractButton createToolbarButton(String key) {

    ImageIcon ii = JmolResourceHandler.getIconX(key + "Image");
    AbstractButton b = new JButton(ii);
    String isToggleString = JmolResourceHandler.getStringX(key + "Toggle");
    if (isToggleString != null) {
        boolean isToggle = Boolean.valueOf(isToggleString).booleanValue();
        if (isToggle) {
            b = new JToggleButton(ii);
            if (key.equals("rotate"))
                buttonRotate = b;
            toolbarButtonGroup.add(b);
            String isSelectedString = JmolResourceHandler.getStringX(key + "ToggleSelected");
            if (isSelectedString != null) {
                boolean isSelected = Boolean.valueOf(isSelectedString).booleanValue();
                b.setSelected(isSelected);
            }
        }
    }
    b.setRequestFocusEnabled(false);
    b.setMargin(new Insets(1, 1, 1, 1));

    Action a = null;
    String actionCommand = null;
    if (key.endsWith("Script")) {
        actionCommand = JmolResourceHandler.getStringX(key);
        a = executeScriptAction;
    } else {
        actionCommand = key;
        a = getAction(key);
    }
    if (a != null) {
        b.setActionCommand(actionCommand);
        b.addActionListener(a);
        a.addPropertyChangeListener(new ActionChangedListener(b));
        b.setEnabled(a.isEnabled());
    } else {
        b.setEnabled(false);
    }

    String tip = guimap.getLabel(key + "Tip");
    if (tip != null) {
        b.setToolTipText(tip);
    }

    return b;
}

From source file:org.pentaho.ui.xul.swing.tags.SwingButton.java

public void setDisabled(boolean dis) {
    final AbstractButton button = getButton();
    boolean previous = !button.isEnabled();
    button.setEnabled(!dis);
    this.changeSupport.firePropertyChange("disabled", previous, dis);
}

From source file:org.pentaho.ui.xul.swing.tags.SwingButton.java

@Override
public void layout() {
    // check type to see if it's a toggleButton
    if (type == Type.CHECKBOX || type == Type.RADIO) {
        final AbstractButton oldButton = getButton();

        final AbstractButton button = new JToggleButton();
        button.setText(oldButton.getText());
        button.setIcon(oldButton.getIcon());
        button.setEnabled(oldButton.isEnabled());
        button.setSelected(this.selected);
        setButton(button);//  ww w.  j av a2 s  .c o  m

        if (this.getOnclick() != null) {
            this.setOnclick(this.getOnclick());
        }
    }
    final AbstractButton button = getButton();
    // adjust orientation of label and icon
    if (this.orientation == Orient.VERTICAL) {
        button.setHorizontalTextPosition(JButton.CENTER);
        if (this.dir == Direction.FORWARD) {
            button.setVerticalTextPosition(JButton.BOTTOM);
        } else {
            button.setVerticalTextPosition(JButton.TOP);
        }
    } else {
        button.setVerticalTextPosition(JButton.CENTER);
        if (this.dir == Direction.FORWARD) {
            button.setHorizontalTextPosition(JButton.RIGHT);
        } else {
            button.setHorizontalTextPosition(JButton.LEFT);
        }
    }

    // Square button patch. if no label and icon is square, set min/max to square up button
    final Icon icon = button.getIcon();
    if ("".equals(button.getText()) && icon != null && icon.getIconHeight() == icon.getIconWidth()) {
        Dimension dim = button.getPreferredSize();
        button.setMinimumSize(new Dimension(dim.height, dim.height));
        button.setPreferredSize(new Dimension(dim.height, dim.height));
    }

    button.setToolTipText(this.getTooltiptext());

    super.layout();
}