Example usage for javax.swing JCheckBox addItemListener

List of usage examples for javax.swing JCheckBox addItemListener

Introduction

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

Prototype

public void addItemListener(ItemListener l) 

Source Link

Document

Adds an ItemListener to the checkbox.

Usage

From source file:Main.java

public Main() {
    // Add check boxes to the content pane.
    Icon normal = new MyIcon(Color.red);
    Icon rollover = new MyIcon(Color.YELLOW);
    Icon selected = new MyIcon(Color.BLUE);

    JCheckBox cb = new JCheckBox(normal);
    cb.setRolloverIcon(rollover);/*from  w  ww. j  a  v a2s .c om*/
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

From source file:Main.java

public Main() {
    // Add check boxes to the content pane.
    Icon normal = new MyIcon(Color.red);
    Icon rollover = new MyIcon(Color.YELLOW);
    Icon selected = new MyIcon(Color.BLUE);

    JCheckBox cb = new JCheckBox(normal, true);
    cb.setRolloverIcon(rollover);/*from  www .j a v  a2 s . c  o  m*/
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

From source file:Main.java

public Main() {
    // Add check boxes to the content pane.
    Icon normal = new MyIcon(Color.red);
    Icon rollover = new MyIcon(Color.YELLOW);
    Icon selected = new MyIcon(Color.BLUE);

    JCheckBox cb = new JCheckBox("www.java2s.com", normal);
    cb.setRolloverIcon(rollover);/* www  .  jav a 2  s.  co  m*/
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

From source file:MainClass.java

public MainClass() {
    // Add check boxes to the content pane.
    Icon normal = new MyIcon(Color.red);
    Icon rollover = new MyIcon(Color.YELLOW);
    Icon selected = new MyIcon(Color.BLUE);

    JCheckBox cb = new JCheckBox("www.java2s.com", normal);
    cb.setRolloverIcon(rollover);//from  w  w w .  j  av a  2 s  .  c o  m
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

From source file:Main.java

public Main() {
    // Add check boxes to the content pane.
    Icon normal = new MyIcon(Color.red);
    Icon rollover = new MyIcon(Color.YELLOW);
    Icon selected = new MyIcon(Color.BLUE);

    JCheckBox cb = new JCheckBox("www.java2s.com", normal, true);
    cb.setRolloverIcon(rollover);/*from  w w  w  .  ja  va2 s .  c  om*/
    cb.setSelectedIcon(selected);
    cb.addItemListener(this);
    add(cb);

}

From source file:ComponentEventDemo.java

public ComponentEventDemo() {
    super(new BorderLayout());

    display = new JTextArea();
    display.setEditable(false);//w ww .  j av a 2 s  . c o  m
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(350, 200));

    JPanel panel = new JPanel(new BorderLayout());
    label = new JLabel("This is a label", JLabel.CENTER);
    label.addComponentListener(this);
    panel.add(label, BorderLayout.CENTER);

    JCheckBox checkbox = new JCheckBox("Label visible", true);
    checkbox.addItemListener(this);
    checkbox.addComponentListener(this);
    panel.add(checkbox, BorderLayout.PAGE_END);
    panel.addComponentListener(this);

    add(scrollPane, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
    frame.addComponentListener(this);
}

From source file:layout.BoxLayoutDemo2.java

public void populateContentPane(Container contentPane) {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));

    //Create the rectangles.
    int shortSideSize = 15;
    for (int i = 0; i < NUM_COMPONENTS; i++) {
        if (sizeIsRandom) {
            shortSideSize = (int) (30.0 * Math.random()) + 30;
        } else {/*from w  ww  .  j  ava 2  s . c  o m*/
            shortSideSize += 10;
        }
        bldComponent[i] = new BLDComponent(xAlignment[i], hue[i], shortSideSize, restrictSize, sizeIsRandom,
                String.valueOf(i));
        panel.add(bldComponent[i]);
    }

    //Create the instructions.
    JLabel label = new JLabel("Click a rectangle to " + "change its X alignment.");
    JCheckBox cb = new JCheckBox("Restrict maximum rectangle size.");
    cb.setSelected(restrictSize);
    cb.addItemListener(this);

    panel.setBorder(BorderFactory.createLineBorder(Color.red));

    Box box = Box.createVerticalBox();
    box.add(label);
    box.add(cb);

    contentPane.add(panel, BorderLayout.CENTER);
    contentPane.add(box, BorderLayout.PAGE_END);
}

From source file:org.uncommons.watchmaker.swing.evolutionmonitor.IslandsView.java

/**
 * Creates the GUI controls for toggling graph display options.
 * @return A component that can be added to the main panel.
 *///from  ww w .  j a va  2 s.c  o  m
private JComponent createControls() {
    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    final JCheckBox meanCheckBox = new JCheckBox("Show Mean and Standard Deviation", false);
    meanCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent itemEvent) {
            chart.setNotify(false);
            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            if (itemEvent.getStateChange() == ItemEvent.SELECTED) {
                plot.setDataset(1, meanDataSet);
                plot.setRenderer(1, meanRenderer);
            } else {
                plot.setDataset(1, null);
                plot.setRenderer(1, null);
            }
            chart.setNotify(true);
        }
    });
    controls.add(meanCheckBox);

    return controls;
}

From source file:org.uncommons.watchmaker.swing.evolutionmonitor.PopulationFitnessView.java

/**
 * Creates the GUI controls for toggling graph display options.
 * @return A component that can be added to the main panel.
 *//*from  www. ja  v a2  s  . c  o  m*/
private JComponent createControls(boolean islands) {
    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    allDataButton.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
            updateDomainAxisRange();
        }
    });
    String text = "Last " + SHOW_FIXED_GENERATIONS + (islands ? " Epochs" : " Generations");
    JRadioButton recentDataButton = new JRadioButton(text, true);
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(allDataButton);
    buttonGroup.add(recentDataButton);

    controls.add(allDataButton);
    controls.add(recentDataButton);

    final JCheckBox meanCheckBox = new JCheckBox("Show Mean", true);
    meanCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent itemEvent) {
            if (itemEvent.getStateChange() == ItemEvent.SELECTED) {
                dataSet.addSeries(meanSeries);
            } else {
                dataSet.removeSeries(meanSeries);
            }
        }
    });
    controls.add(meanCheckBox);

    invertCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent itemEvent) {
            rangeAxis.setInverted(invertCheckBox.isSelected());
        }
    });
    controls.add(invertCheckBox);

    return controls;
}

From source file:com.google.code.facebook.graph.sna.applet.UnicodeLabelDemo.java

public UnicodeLabelDemo() {

    // create a simple graph for the demo
    graph = new DirectedSparseGraph<Integer, Number>();
    Integer[] v = createVertices(10);
    createEdges(v);/*from w  w  w.j a  v a2s . com*/

    vv = new VisualizationViewer<Integer, Number>(new FRLayout<Integer, Number>(graph));
    vv.getRenderContext().setVertexLabelTransformer(new UnicodeVertexStringer<Integer>(v));
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));
    VertexIconShapeTransformer<Integer> vertexIconShapeFunction = new VertexIconShapeTransformer<Integer>(
            new EllipseVertexShapeTransformer<Integer>());
    DefaultVertexIconTransformer<Integer> vertexIconFunction = new DefaultVertexIconTransformer<Integer>();
    vv.getRenderContext().setVertexShapeTransformer(vertexIconShapeFunction);
    vv.getRenderContext().setVertexIconTransformer(vertexIconFunction);
    loadImages(v, vertexIconFunction.getIconMap());
    vertexIconShapeFunction.setIconMap(vertexIconFunction.getIconMap());
    vv.getRenderContext().setVertexFillPaintTransformer(
            new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.white, Color.yellow));
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.lightGray));

    vv.setBackground(Color.white);

    // add my listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<Integer>());

    // create a frome to hold the graph
    final JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>();
    vv.setGraphMouse(gm);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JCheckBox lo = new JCheckBox("Show Labels");
    lo.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            showLabels = e.getStateChange() == ItemEvent.SELECTED;
            vv.repaint();
        }
    });
    lo.setSelected(true);

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    controls.add(lo);
    controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox());
    content.add(controls, BorderLayout.SOUTH);

    frame.pack();
    frame.setVisible(true);
}