Example usage for javax.swing JToggleButton setSelected

List of usage examples for javax.swing JToggleButton setSelected

Introduction

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

Prototype

public void setSelected(boolean b) 

Source Link

Document

Sets the state of the button.

Usage

From source file:ScribbleDragAndDrop.java

/**
 * The main method. Creates a simple application using this class. Note the
 * buttons for switching between draw mode and drag mode.
 *//*from w  ww.j  a  v  a2  s  .  c om*/
public static void main(String[] args) {
    // Create a frame and put a scribble pane in it
    JFrame frame = new JFrame("ScribbleDragAndDrop");
    final ScribbleDragAndDrop scribblePane = new ScribbleDragAndDrop();
    frame.getContentPane().add(scribblePane, BorderLayout.CENTER);

    // Create two buttons for switching modes
    JToolBar toolbar = new JToolBar();
    ButtonGroup group = new ButtonGroup();
    JToggleButton draw = new JToggleButton("Draw");
    JToggleButton drag = new JToggleButton("Drag");
    draw.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scribblePane.setDragMode(false);
        }
    });
    drag.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scribblePane.setDragMode(true);
        }
    });
    group.add(draw);
    group.add(drag);
    toolbar.add(draw);
    toolbar.add(drag);
    frame.getContentPane().add(toolbar, BorderLayout.NORTH);

    // Start off in drawing mode
    draw.setSelected(true);
    scribblePane.setDragMode(false);

    // Pop up the window
    frame.setSize(400, 400);
    frame.setVisible(true);
}

From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java

/**
 * Creates a diminutive toggle button used for selecting the message type
 * //from  w  w  w .  j av  a  2s . c  o  m
 * @param title
 *            the title of the button
 * @param icon
 *            the icon to use
 * @param selected
 *            whether the button is selected or not
 * @param group
 *            the group to add the button to
 * @return the instantiated button
 */
private JToggleButton createMessageTypeButton(String title, ImageIcon icon, boolean selected,
        ButtonGroup group) {
    JToggleButton button = new JToggleButton(icon);
    group.add(button);
    button.setSelected(selected);
    button.setToolTipText(title);
    button.setFocusable(false);
    button.setFocusPainted(false);
    button.addActionListener(this);
    button.setPreferredSize(new Dimension(18, 18));
    return button;
}

From source file:livecanvas.mesheditor.MeshEditor.java

private void setSelectedToolType(int type) {
    Tool prev, next;//from   w w  w  .j  a va  2 s .c  om
    prev = canvas.getSelectedTool();
    canvas.setSelectedToolType(type);
    next = canvas.getSelectedTool();
    JToggleButton toolBtn;
    if (!next.onSelected(this)) {
        toolBtn = findToolButtonByName(prev.name);
        toolBtn.setSelected(true);
        canvas.setSelectedTool(prev);
        return;
    } else if (prev != null) {
        prev.onDeselected(this);
    }
    if (!(toolBtn = findToolButtonByName(next.name)).isSelected()) {
        toolBtn.setSelected(true);
    }
    propertiesPanel.removeAll();
    propertiesPanel.add(new AutoPanel(PropertyFactory.createProperties(next)));
    propertiesPanel.revalidate();
    propertiesPanel.repaint();
}

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

private JPanel getToolsPane() {

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(0, 2));

    ButtonGroup group = new ButtonGroup();
    JToggleButton button = newGrouppedButton(CURSOR_TOOL_ACTION, group);
    button.setSelected(true);
    panel.add(button);//from   w  w w.j a  v a2 s . c  o m
    panel.add(newGrouppedButton(MOVE_VIEWPORT_TOOL_ACTION, group));
    panel.add(newGrouppedButton(WIRES_TOOL_ACTION, group));

    panel.add(newGrouppedButton(AND2_TOOL_ACTION, group));
    panel.add(newGrouppedButton(AND3_TOOL_ACTION, group));
    panel.add(newGrouppedButton(AND4_TOOL_ACTION, group));

    panel.add(newGrouppedButton(OR2_TOOL_ACTION, group));
    panel.add(newGrouppedButton(OR3_TOOL_ACTION, group));
    panel.add(newGrouppedButton(OR4_TOOL_ACTION, group));

    panel.add(newGrouppedButton(XOR2_TOOL_ACTION, group));
    panel.add(newGrouppedButton(XOR3_TOOL_ACTION, group));
    panel.add(newGrouppedButton(XOR4_TOOL_ACTION, group));

    panel.add(newGrouppedButton(NOT_TOOL_ACTION, group));
    panel.add(newGrouppedButton(CLOCK_TOOL_ACTION, group));
    panel.add(newGrouppedButton(FLIP_FLOP_DATA_TOOL_ACTION, group));
    panel.add(newGrouppedButton(SEVEN_SEGMENTS_DISPLAY_TOOL_ACTION, group));
    panel.add(newGrouppedButton(SEVEN_SEGMENTS_DISPLAY_DOUBLE_TOOL_ACTION, group));
    panel.add(newGrouppedButton(TRISTATE_TOOL_ACTION, group));
    panel.add(newGrouppedButton(LED_TOOL_ACTION, group));
    panel.add(newGrouppedButton(TIME_DIAGRAM_TOOL_ACTION, group));
    panel.add(newGrouppedButton(SWITCH_TOOL_ACTION, group));
    return panel;
}

From source file:livecanvas.mesheditor.MeshEditor.java

private JToolBar createTools() {
    JToolBar toolbar = new JToolBar(JToolBar.VERTICAL);
    ButtonGroup toolsBg = new ButtonGroup();
    JToggleButton toolsButton;
    toolbar.add(toolsButton = Utils.createToolBarToggleButton("Brush",
            new ImageIcon(clazz.getResource("res/brush.png")), ButtonType.ICON_ONLY, TOOLS_BRUSH, "Brush",
            toolsBg, this));
    toolsButton.setSelected(true);
    toolbar.add(toolsButton = Utils.createToolBarToggleButton("Pen",
            new ImageIcon(clazz.getResource("res/pen.png")), ButtonType.ICON_ONLY, TOOLS_PEN, "Pen", toolsBg,
            this));
    toolbar.add(toolsButton = Utils.createToolBarToggleButton("MagicWand",
            new ImageIcon(clazz.getResource("res/wand.png")), ButtonType.ICON_ONLY, TOOLS_MAGICWAND,
            "Magic Wand", toolsBg, this));
    toolbar.add(toolsButton = Utils.createToolBarToggleButton("SetControlPoints",
            new ImageIcon(clazz.getResource("res/set_controls.png")), ButtonType.ICON_ONLY,
            TOOLS_SETCONTROLPOINTS, "Set Control Points", toolsBg, this));
    toolbar.add(toolsButton = Utils.createToolBarToggleButton("Pointer",
            new ImageIcon(clazz.getResource("res/pointer.png")), ButtonType.ICON_ONLY, TOOLS_POINTER, "Pointer",
            toolsBg, this));
    toolbar.add(toolsButton = Utils.createToolBarToggleButton("PanZoom",
            new ImageIcon(clazz.getResource("res/panzoom.png")), ButtonType.ICON_ONLY, TOOLS_PANZOOM,
            "Pan or Zoom Canvas", toolsBg, this));
    // toolsButton.setSelected(true);
    return toolbar;
}

From source file:com.t3.client.ui.ExportDialog.java

/**
 * Turn off all JToggleButtons on the form. We don't care if we turn off
 * fields that are normally turned on, since {@link #enforceButtonRules()}
 * will turn them back on as appropriate.
 *///from w w  w . j a v a 2 s.  c o m
private void resetExportSettings() {
    FormAccessor fa = interactPanel.getFormAccessor();
    Iterator<?> iter = fa.beanIterator(true);
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof JToggleButton) {
            JToggleButton jtb = (JToggleButton) obj;
            jtb.setSelected(false);
        }
    }
}

From source file:io.gameover.utilities.pixeleditor.Pixelizer.java

private void selectFrame(int index) {
    if (index >= 0 && index < frames.size()) {
        this.currentFrameIndex = index;
        clearSelection();//from  w  ww  .ja v a 2s  .c o m
        this.savedStates.clear();
        currentStateIndex = 0;
        for (int i = 0; i < this.frames.size(); i++) {
            JToggleButton button = this.selectFrameButtons.get(i);
            if (i != index && button.isSelected()) {
                button.setSelected(false);
            } else if (i == index && !button.isSelected()) {
                button.setSelected(true);
            }
        }
        refreshCurrentColors();
        refresh();
    }
}

From source file:com.t3.client.ui.ExportDialog.java

public void setExportSettings(Map<String, Boolean> settings) {
    resetExportSettings();/*from   w  w  w  . j av a  2s  .c  o  m*/
    if (settings != null) {
        for (String iter : settings.keySet()) {
            JToggleButton jtb = (JToggleButton) interactPanel.getComponentByName(iter);
            if (jtb == null) {
                log.warn("GUI component for export setting '" + iter + "' not found.");
            } else
                jtb.setSelected(settings.get(iter));
        }
    }
}

From source file:org.nbheaven.sqe.codedefects.history.controlcenter.panels.SQEHistoryPanel.java

/** Creates new form SQEHistoryPanel */
public SQEHistoryPanel() {
    historyChart = org.jfree.chart.ChartFactory.createStackedXYAreaChart(null, "Snapshot", "CodeDefects",
            perProjectDataSet, PlotOrientation.VERTICAL, false, true, false);
    historyChart.setBackgroundPaint(Color.WHITE);
    historyChart.getXYPlot().setRangeGridlinePaint(Color.BLACK);
    historyChart.getXYPlot().setDomainGridlinePaint(Color.BLACK);
    historyChart.getXYPlot().setBackgroundPaint(Color.WHITE);

    XYPlot plot = historyChart.getXYPlot();
    plot.setForegroundAlpha(0.7f);/*w ww .  ja  v a2s .com*/
    //        plot.getRenderer();

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects");
    rangeAxis.setStrictValuesFlag(false);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.setRangeAxis(rangeAxis);

    StackedXYAreaRenderer2 categoryItemRenderer = new StackedXYAreaRenderer2(); //3D();
    categoryItemRenderer.setSeriesPaint(0, Color.RED);
    categoryItemRenderer.setSeriesPaint(1, Color.ORANGE);
    categoryItemRenderer.setSeriesPaint(2, Color.YELLOW);

    plot.setRenderer(categoryItemRenderer);

    ChartPanel historyChartPanel = new ChartPanel(historyChart);
    historyChartPanel.setBorder(null);
    historyChartPanel.setPreferredSize(new Dimension(150, 200));
    historyChartPanel.setBackground(Color.WHITE);
    initComponents();

    historyView.setLayout(new BorderLayout());
    historyView.add(historyChartPanel, BorderLayout.CENTER);

    JPanel selectorPanel = new JPanel();
    selectorPanel.setOpaque(false);

    GroupLayout layout = new GroupLayout(selectorPanel);
    selectorPanel.setLayout(layout);

    // Turn on automatically adding gaps between components
    layout.setAutocreateGaps(true);

    // Turn on automatically creating gaps between components that touch
    // the edge of the container and the container.
    layout.setAutocreateContainerGaps(true);

    ParallelGroup horizontalParallelGroup = layout.createParallelGroup(GroupLayout.LEADING);
    SequentialGroup verticalSequentialGroup = layout.createSequentialGroup();

    layout.setHorizontalGroup(layout.createSequentialGroup().add(horizontalParallelGroup));

    layout.setVerticalGroup(verticalSequentialGroup);

    clearHistoryButton = new JButton();
    clearHistoryButton.setEnabled(false);
    clearHistoryButton.setIcon(ImageUtilities
            .image2Icon(ImageUtilities.loadImage("org/nbheaven/sqe/codedefects/history/resources/trash.png")));
    clearHistoryButton.setOpaque(false);
    clearHistoryButton.setFocusPainted(false);
    clearHistoryButton.setToolTipText(
            NbBundle.getBundle("org/nbheaven/sqe/codedefects/history/controlcenter/panels/Bundle")
                    .getString("HINT_clear_button"));
    horizontalParallelGroup.add(clearHistoryButton);
    verticalSequentialGroup.add(clearHistoryButton);
    clearHistoryButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (null != activeHistory) {
                activeHistory.clear();
            }
        }

    });

    Component createVerticalStrut = Box.createVerticalStrut(10);

    horizontalParallelGroup.add(createVerticalStrut);
    verticalSequentialGroup.add(createVerticalStrut);

    for (final QualityProvider provider : SQEUtilities.getProviders()) {
        final JToggleButton providerButton = new JToggleButton();
        providerButton.setIcon(provider.getIcon());
        providerButton.setOpaque(false);
        providerButton.setFocusPainted(false);
        horizontalParallelGroup.add(providerButton);
        verticalSequentialGroup.add(providerButton);
        ActionListener listener = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (providerButton.isSelected()) {
                    addSelectedProvider(provider);
                } else {
                    removeSelectedProvider(provider);
                }
                updateView();
            }
        };
        providerButton.addActionListener(listener);
        addSelectedProvider(provider);
        providerButton.setSelected(true);
    }

    historyView.add(selectorPanel, BorderLayout.EAST);
}

From source file:edu.ku.brc.specify.plugins.latlon.LatLonUI.java

/**
 * Swaps the the proper form into the panel.
 * @param formInx the index of the format that is being used.
 * @param type the type of point, line or Rect being used
 *//* ww w  .j  ava 2 s .  com*/
protected void swapForm(final int formInx, final LatLonUIIFace.LatLonType type) {
    if (currentInx != -1 && currentInx != formInx) {
        FORMAT[] fmts = FORMAT.values();

        FORMAT fromFmt = srcFormat;
        FORMAT toFmt = fmts[formInx];

        DDDDPanel prevPanel1 = panels[(currentInx * 2)];
        DDDDPanel prevPanel2 = panels[(currentInx * 2) + 1];

        DDDDPanel nextPanel1 = panels[(formInx * 2)];
        DDDDPanel nextPanel2 = panels[(formInx * 2) + 1];

        boolean srcFormatHasChanged = prevPanel1.getDefaultFormat() != srcFormat; // same for either panel 1 or 2
        if (type == LatLonUIIFace.LatLonType.LLPoint) {
            if (prevPanel1.hasChanged()) {
                checkPanel(srcFormatHasChanged, prevPanel1, null, srcLatLon1, null, fromFmt, toFmt);

            } else if (srcLatLon1.first == null && srcLatLon1.second == null) {
                srcFormat = nextPanel1.getDefaultFormat();
            }

        } else {
            if (prevPanel1.hasChanged() && !prevPanel2.hasChanged()) {
                checkPanel(srcFormatHasChanged, prevPanel1, prevPanel2, srcLatLon1, srcLatLon2, fromFmt, toFmt);

            } else if (prevPanel2.hasChanged() && !prevPanel1.hasChanged()) {
                checkPanel(srcFormatHasChanged, prevPanel2, prevPanel1, srcLatLon2, srcLatLon1, fromFmt, toFmt);

            } else if (prevPanel1.hasChanged() && prevPanel2.hasChanged()) {
                checkPanel(srcFormatHasChanged, prevPanel1, null, srcLatLon1, null, fromFmt, toFmt);
                checkPanel(srcFormatHasChanged, prevPanel2, null, srcLatLon2, null, fromFmt, toFmt);

            } else if (srcLatLon1.first == null && srcLatLon1.second == null && srcLatLon2.first == null
                    && srcLatLon2.second == null) {
                srcFormat = nextPanel1.getDefaultFormat();
            }
        }

        nextPanel1.set(srcFormat, srcLatLon1.first, srcLatLon1.second);

        if (type == LatLonUIIFace.LatLonType.LLPoint) {
            nextPanel2.clear();

        } else {
            nextPanel2.set(srcFormat, srcLatLon2.first, srcLatLon2.second);
        }
        hasChanged = true;
        stateChanged(null);
        choosenFormat = toFmt;
    }

    // Set the radio button accordingly
    for (JToggleButton rb : selectedTypeHash.keySet()) {
        if (selectedTypeHash.get(rb).ordinal() == type.ordinal()) {
            rb.setSelected(true);
            break;
        }
    }

    JPanel panel = panels[(formInx * 2)];

    cardSubPanes[formInx].removeAll();

    if (type == LatLonUIIFace.LatLonType.LLPoint) {
        cardSubPanes[formInx].add(panel, BorderLayout.CENTER);
        panel.setBorder(panelBorder);

    } else {
        JTabbedPane tabbedPane = (JTabbedPane) latLonPanes[formInx];
        tabbedPane.removeAll();
        cardSubPanes[formInx].add(tabbedPane, BorderLayout.CENTER);
        panel.setBorder(null);

        int inx = type == LatLonUIIFace.LatLonType.LLLine ? 1 : 3;

        tabbedPane.addTab(null, pointImages[inx++], panels[(formInx * 2)]);
        tabbedPane.addTab(null, pointImages[inx], panels[(formInx * 2) + 1]);
    }

    cardPanel.validate();
    cardPanel.doLayout();
    cardPanel.repaint();

    currentInx = formInx;
}