Example usage for javax.swing JToggleButton setText

List of usage examples for javax.swing JToggleButton setText

Introduction

In this page you can find the example usage for javax.swing JToggleButton setText.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The button's text.")
public void setText(String text) 

Source Link

Document

Sets the button's text.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JToolBar toolbar = new JToolBar();
    ImageIcon icon = new ImageIcon("icon.gif");
    Action action = new AbstractAction("Button Label", icon) {
        public void actionPerformed(ActionEvent evt) {
        }//from ww w . j a  va 2  s  .  co  m
    };

    JButton c1 = new JButton(action);
    c1.setText(null);
    c1.setMargin(new Insets(0, 0, 0, 0));
    toolbar.add(c1);

    JToggleButton c2 = new JToggleButton(action);
    c2.setText(null);
    c2.setMargin(new Insets(0, 0, 0, 0));
    toolbar.add(c2);

    JComboBox c3 = new JComboBox(new String[] { "A", "B", "C" });
    c3.setPrototypeDisplayValue("XXXXXXXX"); // Set a desired width
    c3.setMaximumSize(c3.getMinimumSize());
    toolbar.add(c3);
}

From source file:Main.java

/**
 * Creates a {@link JCheckBoxMenuItem} for a menu or {@link JToggleButton}
 * for a tool bar//from  w  w w  .ja  v  a  2 s  .  c  o  m
 * 
 * @param menuOrToolBar
 * @param action 
 * @throws NoSuchMethodException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
public static void addBooleanActionTo(Container menuOrToolBar, Action action) {
    Method addButton;
    try {
        addButton = Container.class.getMethod("add", Component.class);
        if (menuOrToolBar instanceof JMenu) {
            addButton.invoke(menuOrToolBar, new JCheckBoxMenuItem(action));
        } else {
            final JToggleButton jToggleButton = new JToggleButton(action);
            jToggleButton.setText(null);
            addButton.invoke(menuOrToolBar, jToggleButton);
        }
    } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
            | InvocationTargetException e) {
        e.printStackTrace();
    }
}

From source file:components.CrayonPanel.java

protected JToggleButton createCrayon(String name, Border normalBorder) {
    JToggleButton crayon = new JToggleButton();
    crayon.setActionCommand(name);//  w  ww.j  ava2s.c  om
    crayon.addActionListener(this);

    //Set the image or, if that's invalid, equivalent text.
    ImageIcon icon = createImageIcon("images/" + name + ".gif");
    if (icon != null) {
        crayon.setIcon(icon);
        crayon.setToolTipText("The " + name + " crayon");
        crayon.setBorder(normalBorder);
    } else {
        crayon.setText("Image not found. This is the " + name + " button.");
        crayon.setFont(crayon.getFont().deriveFont(Font.ITALIC));
        crayon.setHorizontalAlignment(JButton.HORIZONTAL);
        crayon.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    }

    return crayon;
}

From source file:cl.almejo.vsim.gui.SimWindow.java

private JToggleButton newGrouppedButton(Action action, ButtonGroup group) {
    JToggleButton button = new JToggleButton();
    button.setAction(action);/*www  .  java  2 s  .c  om*/
    button.setText("");
    group.add(button);
    return button;
}

From source file:com.rapidminer.gui.properties.OperatorPropertyPanel.java

@Override
public Component getComponent() {
    if (dockableComponent == null) {
        JScrollPane scrollPane = new ExtendedJScrollPane(this);
        scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setBorder(null);/*w w  w.  java 2 s. co  m*/

        dockableComponent = new JPanel(new BorderLayout());

        JPanel toolBarPanel = new JPanel(new BorderLayout());
        ViewToolBar toolBar = new ViewToolBar();
        JToggleButton toggleExpertModeButton = mainFrame.TOGGLE_EXPERT_MODE_ACTION.createToggleButton();
        toggleExpertModeButton.setText(null);
        toolBar.add(toggleExpertModeButton);

        showHelpAction.setSelected(isShowParameterHelp());
        JToggleButton helpToggleButton = showHelpAction.createToggleButton();
        helpToggleButton.setText(null);
        toolBar.add(helpToggleButton);

        Action infoOperatorAction = new InfoOperatorAction() {

            private static final long serialVersionUID = 6758272768665592429L;

            @Override
            protected Operator getOperator() {
                return mainFrame.getFirstSelectedOperator();
            }
        };
        toolBar.add(infoOperatorAction);
        JToggleButton enableOperatorButton = new ToggleActivationItem(mainFrame.getActions())
                .createToggleButton();
        enableOperatorButton.setText(null);
        toolBar.add(enableOperatorButton);
        Action renameOperatorAction = new ResourceAction(true, "rename_in_processrenderer") {

            {
                setCondition(OPERATOR_SELECTED, MANDATORY);
            }

            private static final long serialVersionUID = -3104160320178045540L;

            @Override
            public void actionPerformed(ActionEvent e) {
                Operator operator = mainFrame.getFirstSelectedOperator();
                String name = SwingTools.showInputDialog("rename_operator", operator.getName());
                if (name != null && name.length() > 0) {
                    operator.rename(name);
                }
            }
        };
        toolBar.add(renameOperatorAction);
        toolBar.add(new DeleteOperatorAction());
        breakpointButton.addToToolBar(toolBar);

        // toolBar.add(mainFrame.getActions().MAKE_DIRTY_ACTION);
        toolBarPanel.add(toolBar, BorderLayout.NORTH);

        JPanel headerPanel = new JPanel();
        headerPanel.setBackground(SwingTools.LIGHTEST_BLUE);
        headerPanel.add(headerLabel);
        headerPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY));
        toolBarPanel.add(headerPanel, BorderLayout.SOUTH);

        dockableComponent.add(toolBarPanel, BorderLayout.NORTH);
        dockableComponent.add(scrollPane, BorderLayout.CENTER);

        // compatibility level and warnings
        JPanel southPanel = new JPanel(new BorderLayout());
        southPanel.add(expertModeHintLabel, BorderLayout.CENTER);
        compatibilityLabel.setLabelFor(compatibilityLevelSpinner);
        compatibilityLevelSpinner.setPreferredSize(
                new Dimension(80, (int) compatibilityLevelSpinner.getPreferredSize().getHeight()));
        compatibilityPanel.add(compatibilityLabel);
        compatibilityPanel.add(compatibilityLevelSpinner);
        southPanel.add(compatibilityPanel, BorderLayout.SOUTH);

        dockableComponent.add(southPanel, BorderLayout.SOUTH);
    }
    return dockableComponent;
}

From source file:com.mightypocket.ashot.Mediator.java

@Action(name = ACTION_RECORDING, enabledProperty = PROP_CONNECTED, selectedProperty = PROP_RECORDING)
public void recording() {
    if (StringUtils.isBlank(p.get(PREF_DEFAULT_FILE_FOLDER, null))) {
        String f = requestDefaultFolder();
        if (StringUtils.isBlank(f)) {
            setRecording(false);/*from  ww w  .  j a  v  a  2  s .  co  m*/
            return;
        }
        p.put(PREF_DEFAULT_FILE_FOLDER, f);
    }

    demon.resetLastImage();
    JToggleButton bt = (JToggleButton) toolBarMap.get(ACTION_RECORDING);
    ResourceMap resourceMap = application.getContext().getResourceMap(Mediator.class);
    if (isRecording()) {
        bt.setText(resourceMap.getString("recording.Action.selectedText"));
    } else {
        bt.setText(resourceMap.getString("recording.Action.text"));
    }
}

From source file:es.emergya.ui.gis.CustomMapView.java

public CustomMapView() {
    super();/*from   w  w w  .  ja va2  s.  c  o m*/
    menu = new MainMenu();
    contentPane.add(panel, BorderLayout.CENTER);

    // iniciar los controles mostrar/ocultar capas
    layerControls = new LinkedList<JToggleButton>();

    JToggleButton botonMostrarOcultarBotones = new JToggleButton(getI18n().getString("map.layers.hideButtons"),
            LogicConstants.getIcon("capas_button_mostrar"), false);
    botonMostrarOcultarBotones.setSelected(true);
    botonMostrarOcultarBotones.setActionCommand("#hide");
    // b.setVerticalTextPosition(SwingConstants.BOTTOM);
    // b.setHorizontalTextPosition(SwingConstants.CENTER);
    botonMostrarOcultarBotones.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JToggleButton b = (JToggleButton) e.getSource();
            if (e.getActionCommand().equals("#hide")) {
                layerControlPanel.removeAll();
                layerControlPanel.add(Box.createHorizontalStrut(10));
                layerControlPanel.add(b);
                b.setActionCommand("#show");
                b.setText(getI18n().getString("map.layers.showButtons"));
            } else {
                layerControlPanel.removeAll();
                layerControlPanel.add(Box.createHorizontalStrut(10));
                for (JToggleButton bt : layerControls) {
                    layerControlPanel.add(bt);
                    layerControlPanel.add(Box.createHorizontalGlue());
                }
                b.setActionCommand("#hide");
                b.setText(getI18n().getString("map.layers.hideButtons"));
            }
            layerControlPanel.updateUI();
        }
    });
    layerControls.add(botonMostrarOcultarBotones);

    final JToggleButton botonTodoasLasCapas = new JToggleButton(getI18n().getString("map.layers.allLayers"),
            LogicConstants.getIcon("capas_button_mostrar"), false);
    layerDialog = new LayerSelectionDialog(this);
    layerDialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            botonTodoasLasCapas.setSelected(false);
        }
    });
    botonTodoasLasCapas.setSelected(false);
    botonTodoasLasCapas.setActionCommand("#all");
    // all.setVerticalTextPosition(SwingConstants.BOTTOM);
    // all.setHorizontalTextPosition(SwingConstants.CENTER);
    botonTodoasLasCapas.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            layerDialog.setLocationRelativeTo((Component) e.getSource());
            layerDialog.setVisible(!layerDialog.isShowing());
        }
    });
    layerControls.add(botonTodoasLasCapas);

    layerControlPanel = new JPanel();
    layerControlPanel.setLayout(new BoxLayout(layerControlPanel, BoxLayout.X_AXIS));

    Main.main.menu = this.menu;
    toolbar = new ToolbarPreferences();
    toolbar.refreshToolbarControl();
    // toolbar.control.updateUI();
    // contentPane.add(toolbar.control, BorderLayout.NORTH);

    contentPane.updateUI();
    panel.updateUI();
}

From source file:com.maxl.java.amikodesk.AMiKoDesk.java

private static void setupButton(JToggleButton button, String toolTipText, String rolloverImg,
        String selectedImg) {//from  w  w  w  .j  a v  a2  s .c  om
    button.setFont(new Font("Dialog", Font.PLAIN, 12));
    button.setVerticalTextPosition(SwingConstants.BOTTOM);
    button.setHorizontalTextPosition(SwingConstants.CENTER);
    button.setText(toolTipText);
    button.setRolloverIcon(new ImageIcon(Constants.IMG_FOLDER + rolloverImg));
    button.setSelectedIcon(new ImageIcon(Constants.IMG_FOLDER + selectedImg));
    button.setBackground(m_selected_but_color);
    button.setToolTipText(toolTipText);

    // Remove border
    Border emptyBorder = BorderFactory.createEmptyBorder();
    button.setBorder(emptyBorder);
    // Set adequate size
    button.setPreferredSize(new Dimension(32, 32));
}

From source file:org.ngrinder.recorder.ui.RecordingControlPanel.java

/**
 * Create "Start Recording" Button and attach the event handler.
 * //from ww  w  .j  a v a  2  s .  c  o m
 * @return created Button.
 */
private JToggleButton createRecordingButton() {
    JToggleButton button = decoratedToSimpleButton(new JToggleButton("Start Recording"));
    button.setText("Start Recording");
    button.setSelected(false);
    button.setMinimumSize(new Dimension(100, 30));
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JToggleButton button = (JToggleButton) e.getSource();
            if (button.isSelected()) {
                button.setText("Stop Recording");
                button.setSelected(true);
                messageBus.getPublisher(Topics.START_RECORDING).propertyChange(new PropertyChangeEvent(
                        RecordingControlPanel.this, "Start Recording", null, getFilteredFileTypes()));
            } else {
                if (!stopConfirm()) {
                    button.setSelected(true);
                    return;
                }
                messageBus.getPublisher(Topics.STOP_RECORDING)
                        .propertyChange(new PropertyChangeEvent(RecordingControlPanel.this, "Stop Recording",
                                null, Pair.of(getFilteredFileTypes(), getGenerationOption())));
                button.setText("Start Recording");
            }
        }
    });
    return button;
}

From source file:org.paxle.desktop.impl.dialogues.cconsole.CrawlingConsole.java

public void actionPerformed(ActionEvent e) {
    final String ac = e.getActionCommand();
    if (ac == AC_CLEAR) {
        clear();/*from   w w w .  j  a  va2  s.c  o  m*/
    } else if (ac == AC_CRAWL) {
        updateCpb(cpb.isSelected(), false, true);
    } else if (ac == AC_SELECT) {
        updateCpb(false, true, false);
    } else if (ac == AC_SETTINGS) {
        final JToggleButton btn = (JToggleButton) e.getSource();
        final boolean sel = btn.isSelected();
        btn.setText(((sel) ? '\u2191' : '\u2193') + btn.getText().substring(1));
        final boolean notInitialized = sel && options.getComponentCount() == 0;
        if (notInitialized)
            initOptions();
        final Runnable sr = new Runnable() {
            public void run() {
                int height = options.getHeight();
                frame.setSize(frame.getWidth(), frame.getHeight() + ((sel) ? height : -height));
            }
        };
        if (!notInitialized)
            sr.run();
        options.setVisible(sel);
        if (notInitialized)
            SwingUtilities.invokeLater(sr);

    }
    if (ac == AC_SELECT || ac == AC_ENQUEUED || ac == AC_DESTROYED) {
        final String compItem = (String) cbox.getSelectedItem();
        final boolean enq = cbEnq.isSelected();
        final boolean dstr = cbDstr.isSelected();
        if (logger.isDebugEnabled())
            logger.debug("received ActionEvent, item: '" + compItem + "', enq: " + enq + ", dstr: " + dstr);
        updateListeners(MWComponents.valueOfHumanReadable(compItem), enq, dstr);
        /*
        model.setType((cbDstr.isSelected()) ? TableDisplay.REJECTED : (cbEnq.isSelected()) ? TableDisplay.WORKING_ON
              : new TableColumns());
              */
    }
}