Example usage for javax.swing JCheckBox addActionListener

List of usage examples for javax.swing JCheckBox addActionListener

Introduction

In this page you can find the example usage for javax.swing JCheckBox addActionListener.

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:AddCheckBoxAction.java

public void addNewCheckBox() {
    JCheckBox chBox = new JCheckBox("CheckBox " + (this.checkBoxes.size() + 1));
    chBox.addActionListener(new CheckBoxAction(this.checkBoxes.size() + 1));
    checkBoxes.add(chBox);/* w w w.  ja va  2s .  c om*/
    add(chBox);
    revalidate();
}

From source file:BoxLayoutTest.java

public JCheckBox addCheckBox(JPanel p, String name) {
    JCheckBox checkBox = new JCheckBox(name);
    checkBox.addActionListener(this);
    p.add(checkBox);/*from   w w w  . ja  v  a 2s .c  o m*/
    return checkBox;
}

From source file:MessageDigestTest.java

public void addCheckBox(Container c, String name, ButtonGroup g, boolean selected, ActionListener listener) {
    JCheckBox b = new JCheckBox(name, selected);
    c.add(b);/*from w ww. j  ava2  s  .  c o  m*/
    g.add(b);
    b.addActionListener(listener);
}

From source file:EditorPaneTest.java

public EditorPaneFrame() {
    setTitle("EditorPaneTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    final Stack<String> urlStack = new Stack<String>();
    final JEditorPane editorPane = new JEditorPane();
    final JTextField url = new JTextField(30);

    // set up hyperlink listener

    editorPane.setEditable(false);/*from   ww w . jav  a2 s. c o m*/
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    // remember URL for back button
                    urlStack.push(event.getURL().toString());
                    // show URL in text field
                    url.setText(event.getURL().toString());
                    editorPane.setPage(event.getURL());
                } catch (IOException e) {
                    editorPane.setText("Exception: " + e);
                }
            }
        }
    });

    // set up checkbox for toggling edit mode

    final JCheckBox editable = new JCheckBox();
    editable.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            editorPane.setEditable(editable.isSelected());
        }
    });

    // set up load button for loading URL

    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                // remember URL for back button
                urlStack.push(url.getText());
                editorPane.setPage(url.getText());
            } catch (IOException e) {
                editorPane.setText("Exception: " + e);
            }
        }
    };

    JButton loadButton = new JButton("Load");
    loadButton.addActionListener(listener);
    url.addActionListener(listener);

    // set up back button and button action

    JButton backButton = new JButton("Back");
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (urlStack.size() <= 1)
                return;
            try {
                // get URL from back button
                urlStack.pop();
                // show URL in text field
                String urlString = urlStack.peek();
                url.setText(urlString);
                editorPane.setPage(urlString);
            } catch (IOException e) {
                editorPane.setText("Exception: " + e);
            }
        }
    });

    add(new JScrollPane(editorPane), BorderLayout.CENTER);

    // put all control components in a panel

    JPanel panel = new JPanel();
    panel.add(new JLabel("URL"));
    panel.add(url);
    panel.add(loadButton);
    panel.add(backButton);
    panel.add(new JLabel("Editable"));
    panel.add(editable);

    add(panel, BorderLayout.SOUTH);
}

From source file:lisong_mechlab.view.graphs.PayloadGraphPanel.java

public PayloadGraphPanel(PayloadStatistics aPayloadStatistics, final JCheckBox aSpeedTweak) {
    super(makeChart(new DefaultTableXYDataset()));
    aSpeedTweak.addActionListener(new ActionListener() {
        @Override/*from  w w  w  .ja  v a2  s .c  o  m*/
        public void actionPerformed(ActionEvent aArg0) {
            efficiencies.setSpeedTweak(aSpeedTweak.isSelected(), null);
            updateGraph();
        }
    });
    payloadStatistics = aPayloadStatistics;
}

From source file:org.esa.beam.smos.visat.GridPointBtDataChartToolView.java

@Override
protected JComponent createGridPointComponentOptionsComponent() {
    modeCheckers = new JCheckBox[] { new JCheckBox("X", true), new JCheckBox("Y", true),
            new JCheckBox("XY", true), };
    final JPanel optionsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 2));
    for (JCheckBox modeChecker : modeCheckers) {
        modeChecker.addActionListener(new ActionListener() {
            @Override/*  ww w  .  ja va 2s.c  om*/
            public void actionPerformed(ActionEvent e) {
                updateGridPointBtDataComponent();
            }
        });
        optionsPanel.add(modeChecker);
    }
    return optionsPanel;
}

From source file:components.TableSelectionDemo.java

private JCheckBox addCheckBox(String text) {
    JCheckBox checkBox = new JCheckBox(text);
    checkBox.addActionListener(this);
    add(checkBox);//from   w  w w  . j  ava2s .com
    return checkBox;
}

From source file:org.esa.smos.gui.gridpoint.GridPointBtDataChartTopComponent.java

@Override
protected JComponent createGridPointComponentOptionsComponent() {
    modeCheckers = new JCheckBox[] { new JCheckBox("X", true), new JCheckBox("Y", true),
            new JCheckBox("XY", true), };
    final JPanel optionsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 2));
    for (JCheckBox modeChecker : modeCheckers) {
        modeChecker.addActionListener(e -> updateGridPointBtDataComponent());
        optionsPanel.add(modeChecker);/* w ww  .j  a  va  2 s .  c o m*/
    }
    return optionsPanel;
}

From source file:edu.gmu.cs.sim.util.media.chart.SeriesAttributes.java

/** Builds a SeriesAttributes with the provided generator, name for the series, and index for the series.  Calls
 buildAttributes to construct custom elements in the LabelledList, then finally calls rebuildGraphicsDefinitions()
 to update the series. *//*from  www .  ja v a2s .  c  o m*/
public SeriesAttributes(ChartGenerator generator, String name, int index, SeriesChangeListener stoppable) {
    super(name);
    setStoppable(stoppable);
    this.generator = generator;
    seriesIndex = index;
    final JCheckBox check = new JCheckBox();
    check.setSelected(true);
    check.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setPlotVisible(check.isSelected());
        }
    });

    manipulators = new Box(BoxLayout.X_AXIS);
    buildManipulators();
    JLabel spacer = new JLabel("");
    spacer.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
    Box b = new Box(BoxLayout.X_AXIS);
    b.add(check);
    b.add(spacer);
    b.add(manipulators);
    b.add(Box.createGlue());
    addLabelled("Show", b);

    final PropertyField nameF = new PropertyField(name) {
        public String newValue(String newValue) {
            SeriesAttributes.this.setSeriesName(newValue);
            rebuildGraphicsDefinitions();
            return newValue;
        }
    };
    addLabelled("Series", nameF);

    buildAttributes();
    rebuildGraphicsDefinitions();
}

From source file:MainClass.java

public MainClass() {
    JToggleButton tog = new JToggleButton("ToggleButton");
    JCheckBox cb = new JCheckBox("CheckBox");
    JRadioButton radio = new JRadioButton("RadioButton");

    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);//from  w  w w  .  jav  a  2 s  .  c o m
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    undoButton.setEnabled(false);
    redoButton.setEnabled(false);

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.undo();
            } catch (CannotUndoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                edit.redo();
            } catch (CannotRedoException ex) {
                ex.printStackTrace();
            } finally {
                undoButton.setEnabled(edit.canUndo());
                redoButton.setEnabled(edit.canRedo());
            }
        }
    });

    Box undoRedoBox = new Box(BoxLayout.X_AXIS);
    undoRedoBox.add(Box.createGlue());
    undoRedoBox.add(undoButton);
    undoRedoBox.add(Box.createHorizontalStrut(2));
    undoRedoBox.add(redoButton);
    undoRedoBox.add(Box.createGlue());

    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(buttonBox, BorderLayout.CENTER);
    content.add(undoRedoBox, BorderLayout.SOUTH);
    setSize(400, 150);
}