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:UndoableToggleApp2.java

public UndoableToggleApp2() {
    JToggleButton tog = new JToggleButton("ToggleButton");
    JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox");
    JRadioButton radio = new JRadioButton("RadioButton");

    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);// w ww .  ja  va  2  s .  c om
    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);
    endButton.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());
            }
        }
    });

    endButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit.end();
            endButton.setEnabled(false);
            undoButton.setEnabled(edit.canUndo());
            redoButton.setEnabled(edit.canRedo());
        }
    });

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

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

From source file:org.jfree.chart.demo.Bottom_panel.java

/**
 * Create the panel./*from w w  w .j ava 2 s  .  co  m*/
 */
public Bottom_panel(ArrayList<Graphic> Grafs, ArrayList<XYSeries> series, int x, int y, int width, int height) {

    graf = Grafs.get(8);
    serie = series;
    setBounds(x, y, width, height);
    setLayout(new GridLayout(0, 4, 2, 0));
    final JCheckBox chckbxNewCheckBox_5 = new JCheckBox("Graph 1");
    chckbxNewCheckBox_5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

            XYSeries sr = serie.get(0);

            if (chckbxNewCheckBox_5.isSelected() == true) {

                graf.change_data(serie.get(0), true);
            } else {
                graf.change_data(serie.get(0), false);
            }
        }
    });
    chckbxNewCheckBox_5.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_5);

    final JCheckBox chckbxNewCheckBox_1 = new JCheckBox("Graph2");
    chckbxNewCheckBox_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

            XYSeries sr = serie.get(1);

            if (chckbxNewCheckBox_1.isSelected() == true) {

                graf.change_data(serie.get(1), true);
            } else {
                graf.change_data(serie.get(1), false);
            }
        }

    });
    chckbxNewCheckBox_1.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_1);

    final JCheckBox chckbxNewCheckBox_2 = new JCheckBox("Graph 3");
    chckbxNewCheckBox_2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(2);

            if (chckbxNewCheckBox_2.isSelected() == true) {

                graf.change_data(serie.get(2), true);
            } else {
                graf.change_data(serie.get(2), false);
            }
        }

    });
    chckbxNewCheckBox_2.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_2);

    final JCheckBox chckbxNewCheckBox = new JCheckBox("Graph 4");
    chckbxNewCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(3);

            if (chckbxNewCheckBox.isSelected() == true) {

                graf.change_data(serie.get(3), true);
            } else {
                graf.change_data(serie.get(3), false);
            }
        }

    });
    chckbxNewCheckBox.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox);

    final JCheckBox chckbxNewCheckBox_3 = new JCheckBox("Graph 5");
    chckbxNewCheckBox_3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(4);

            if (chckbxNewCheckBox_3.isSelected() == true) {

                graf.change_data(serie.get(4), true);
            } else {
                graf.change_data(serie.get(4), false);
            }
        }

    });
    chckbxNewCheckBox_3.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_3);

    final JCheckBox chckbxNewCheckBox_4 = new JCheckBox("Graph 6");
    chckbxNewCheckBox_4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(5);

            if (chckbxNewCheckBox_4.isSelected() == true) {

                graf.change_data(serie.get(5), true);
            } else {
                graf.change_data(serie.get(5), false);
            }
        }
    });
    chckbxNewCheckBox_4.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_4);

    final JCheckBox chckbxNewCheckBox_6 = new JCheckBox("Graph 7");
    chckbxNewCheckBox_6.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(6);

            if (chckbxNewCheckBox_6.isSelected() == true) {

                graf.change_data(serie.get(6), true);
            } else {
                graf.change_data(serie.get(6), false);
            }
        }

    });
    chckbxNewCheckBox_6.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_6);

    final JCheckBox chckbxNewCheckBox_7 = new JCheckBox("Graph 8");
    chckbxNewCheckBox_7.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            XYSeries sr = serie.get(7);

            if (chckbxNewCheckBox_6.isSelected() == true) {

                graf.change_data(serie.get(7), true);
            } else {
                graf.change_data(serie.get(7), false);
            }
        }

    });
    chckbxNewCheckBox_7.setBackground(new Color(176, 199, 246));
    add(chckbxNewCheckBox_7);

}

From source file:com.romraider.logger.ecu.ui.handler.graph.GraphUpdateHandler.java

public GraphUpdateHandler(final JPanel panel) {
    this.graphPanel = new JPanel(new SpringLayout());
    final JCheckBox combinedCheckbox = new JCheckBox("Combine Graphs", combinedChart);
    combinedCheckbox.addActionListener(new CombinedActionListener(combinedCheckbox));
    JToggleButton playPauseButton = new JToggleButton("Pause Graphs");
    playPauseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            paused = !paused;//from  ww w.j  a v  a2 s .  c  o m
            if (paused) {
                pauseStartTime = System.currentTimeMillis();
            } else {
                startTime = startTime + (System.currentTimeMillis() - pauseStartTime);
            }
        }
    });
    panel.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(getKeyStroke("F12"), "toggleCombineGraphs");
    panel.getActionMap().put("toggleCombineGraphs", new AbstractAction() {
        private static final long serialVersionUID = 1540427179539775534L;

        public void actionPerformed(ActionEvent e) {
            combinedCheckbox.doClick();
        }
    });
    JPanel controlPanel = new JPanel();
    controlPanel.add(combinedCheckbox);
    controlPanel.add(playPauseButton);
    panel.add(controlPanel, NORTH);
    panel.add(this.graphPanel, CENTER);
}

From source file:UndoableToggleApp.java

public UndoableToggleApp() {

    // Create some toggle buttons (and subclasses)
    JToggleButton tog = new JToggleButton("ToggleButton");
    JCheckBox cb = new JCheckBox("CheckBox");
    JRadioButton radio = new JRadioButton("RadioButton");

    // Add our listener to each toggle button
    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);//w w w . j  a  va2 s  .  c o m
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    // Layout the buttons
    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    // Create undo and redo buttons (initially disabled)
    undoButton = new JButton("Undo");
    redoButton = new JButton("Redo");
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);

    // Add a listener to the undo button. It attempts to call undo() on the
    // current edit, then enables/disables the undo/redo buttons as
    // appropriate.
    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());
            }
        }
    });

    // Add a redo listener: just like the undo listener, but for redo this
    // time.
    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());
            }
        }
    });

    // Layout the undo/redo buttons
    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());

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

From source file:MainClass.java

public MainClass() {
    super("Selection Model Test");
    setSize(450, 350);/*from   w  ww .  ja  v a  2 s.  c om*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    TableModel tm = new AbstractTableModel() {
        public int getRowCount() {
            return 10;
        }

        public int getColumnCount() {
            return 10;
        }

        public Object getValueAt(int r, int c) {
            return "0";
        }
    };

    final JTable jt = new JTable(tm);

    JScrollPane jsp = new JScrollPane(jt);
    getContentPane().add(jsp, BorderLayout.CENTER);

    JPanel controlPanel, buttonPanel, columnPanel, rowPanel;

    buttonPanel = new JPanel();
    final JCheckBox cellBox, columnBox, rowBox;
    cellBox = new JCheckBox("Cells", jt.getCellSelectionEnabled());
    columnBox = new JCheckBox("Columns", jt.getColumnSelectionAllowed());
    rowBox = new JCheckBox("Rows", jt.getRowSelectionAllowed());

    cellBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setCellSelectionEnabled(cellBox.isSelected());
            columnBox.setSelected(jt.getColumnSelectionAllowed());
            rowBox.setSelected(jt.getRowSelectionAllowed());
        }
    });

    columnBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setColumnSelectionAllowed(columnBox.isSelected());
            cellBox.setSelected(jt.getCellSelectionEnabled());
        }
    });

    rowBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setRowSelectionAllowed(rowBox.isSelected());
            cellBox.setSelected(jt.getCellSelectionEnabled());
        }
    });

    buttonPanel.add(new JLabel("Selections allowed:"));
    buttonPanel.add(cellBox);
    buttonPanel.add(columnBox);
    buttonPanel.add(rowBox);

    columnPanel = new JPanel();
    ListSelectionModel csm = jt.getColumnModel().getSelectionModel();
    JLabel columnCounter = new JLabel("Selected Column Indices:");
    csm.addListSelectionListener(new SelectionDebugger(columnCounter, csm));
    columnPanel.add(new JLabel("Selected columns:"));
    columnPanel.add(columnCounter);

    rowPanel = new JPanel();
    ListSelectionModel rsm = jt.getSelectionModel();
    JLabel rowCounter = new JLabel("Selected Row Indices:");
    rsm.addListSelectionListener(new SelectionDebugger(rowCounter, rsm));
    rowPanel.add(new JLabel("Selected rows:"));
    rowPanel.add(rowCounter);

    controlPanel = new JPanel(new GridLayout(0, 1));
    controlPanel.add(buttonPanel);
    controlPanel.add(columnPanel);
    controlPanel.add(rowPanel);

    getContentPane().add(controlPanel, BorderLayout.SOUTH);
}

From source file:es.emergya.ui.plugins.LayerSelectionDialog.java

private void initOptions(final JPanel list) {
    SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {

        @Override//from www.j  ava  2 s. co m
        protected Object doInBackground() throws Exception {
            publish(new Object[0]);
            for (CapaInformacion ci : CapaConsultas.getAllOrderedByOrden()) {
                if (ci.getOpcional() && ci.getHabilitada()) {
                    layers.add(new LayerElement(ci.getNombre(), ci.getUrl(), wasVisible(ci)));
                }
            }
            return null;
        }

        @Override
        protected void process(List<Object> chunks) {
            actualizando.setIcon(es.emergya.cliente.constants.LogicConstants.getIcon("anim_actualizando"));
        }

        @Override
        protected void done() {
            super.done();
            actualizando.setIcon(null);
            list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
            for (LayerElement le : layers) {
                JCheckBox cb = new JCheckBox(le.name, le.active);
                cb.setBackground(Color.WHITE);
                cb.addActionListener(LayerSelectionDialog.this);
                list.add(cb);
                list.revalidate();
            }

            // self.pack();
        }
    };
    sw.execute();
}

From source file:SelectionExample.java

public SelectionExample() {
    super("Selection Model Test");
    setSize(450, 350);//www .j  a  v  a 2s.c  o m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    TableModel tm = new AbstractTableModel() {
        // We'll create a simple multiplication table to serve as a
        // noneditable
        // table with several rows and columns
        public int getRowCount() {
            return 10;
        }

        public int getColumnCount() {
            return 10;
        }

        public Object getValueAt(int r, int c) {
            return "" + (r + 1) * (c + 1);
        }
    };

    final JTable jt = new JTable(tm);

    JScrollPane jsp = new JScrollPane(jt);
    getContentPane().add(jsp, BorderLayout.CENTER);

    // Now set up our selection controls
    JPanel controlPanel, buttonPanel, columnPanel, rowPanel;

    buttonPanel = new JPanel();
    final JCheckBox cellBox, columnBox, rowBox;
    cellBox = new JCheckBox("Cells", jt.getCellSelectionEnabled());
    columnBox = new JCheckBox("Columns", jt.getColumnSelectionAllowed());
    rowBox = new JCheckBox("Rows", jt.getRowSelectionAllowed());
    cellBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setCellSelectionEnabled(cellBox.isSelected());
            columnBox.setSelected(jt.getColumnSelectionAllowed());
            rowBox.setSelected(jt.getRowSelectionAllowed());
        }
    });

    columnBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setColumnSelectionAllowed(columnBox.isSelected());
            cellBox.setSelected(jt.getCellSelectionEnabled());
        }
    });

    rowBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            jt.setRowSelectionAllowed(rowBox.isSelected());
            cellBox.setSelected(jt.getCellSelectionEnabled());
        }
    });

    buttonPanel.add(new JLabel("Selections allowed:"));
    buttonPanel.add(cellBox);
    buttonPanel.add(columnBox);
    buttonPanel.add(rowBox);

    columnPanel = new JPanel();
    ListSelectionModel csm = jt.getColumnModel().getSelectionModel();
    JLabel columnCounter = new JLabel("(Selected Column Indices Go Here)");
    csm.addListSelectionListener(new SelectionDebugger(columnCounter, csm));
    columnPanel.add(new JLabel("Selected columns:"));
    columnPanel.add(columnCounter);

    rowPanel = new JPanel();
    ListSelectionModel rsm = jt.getSelectionModel();
    JLabel rowCounter = new JLabel("(Selected Row Indices Go Here)");
    rsm.addListSelectionListener(new SelectionDebugger(rowCounter, rsm));
    rowPanel.add(new JLabel("Selected rows:"));
    rowPanel.add(rowCounter);

    controlPanel = new JPanel(new GridLayout(0, 1));
    controlPanel.add(buttonPanel);
    controlPanel.add(columnPanel);
    controlPanel.add(rowPanel);

    getContentPane().add(controlPanel, BorderLayout.SOUTH);
}

From source file:UndoableToggleApp2.java

public UndoableToggleApp2() {

    // Create some toggle buttons (and subclasses)
    JToggleButton tog = new JToggleButton("ToggleButton");
    JCheckBox cb = new JCheckBox("CompoundEdit ExampleCheckBox");
    JRadioButton radio = new JRadioButton("RadioButton");

    // Add our listener to each toggle button
    SimpleListener sl = new SimpleListener();
    tog.addActionListener(sl);/*from  w w  w  .j  av  a  2 s .  co m*/
    cb.addActionListener(sl);
    radio.addActionListener(sl);

    // Lay out the buttons
    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    buttonBox.add(tog);
    buttonBox.add(cb);
    buttonBox.add(radio);

    // Create undo and redo buttons (initially disabled)
    undoButton = new JButton("Undo");
    redoButton = new JButton("Redo");
    endButton = new JButton("End");
    undoButton.setEnabled(false);
    redoButton.setEnabled(false);
    endButton.setEnabled(false);

    // Add a listener to the undo button. It attempts to call undo() on the
    // current edit, then enables/disables the undo/redo buttons as
    // appropriate.
    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());
            }
        }
    });

    // Add a redo listener: just like the undo listener, but for redo this
    // time.
    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());
            }
        }
    });

    // Add an end listener. This listener will call end() on the
    // CompoundEdit
    // and update the undo/redo buttons.
    endButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            edit.end();
            endButton.setEnabled(false);
            undoButton.setEnabled(edit.canUndo());
            redoButton.setEnabled(edit.canRedo());
        }
    });

    // Layout the undo/redo/end buttons
    Box undoRedoEndBox = new Box(BoxLayout.X_AXIS);
    undoRedoEndBox.add(Box.createGlue());
    undoRedoEndBox.add(undoButton);
    undoRedoEndBox.add(Box.createHorizontalStrut(2));
    undoRedoEndBox.add(redoButton);
    undoRedoEndBox.add(Box.createHorizontalStrut(2));
    undoRedoEndBox.add(endButton);
    undoRedoEndBox.add(Box.createGlue());

    // Layout the main frame
    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(buttonBox, BorderLayout.CENTER);
    content.add(undoRedoEndBox, BorderLayout.SOUTH);
    setSize(400, 150);
}

From source file:projects.upc.exec.HrDiagram.java

/**
 * Main constructor./*from w  w  w.  j a va2 s.c  om*/
 */
public HrDiagram() {

    List<UpcStar> upcStars = UpcUtils.loadUpcCatalogue();
    List<UpcStar> hipStars = UpcUtils.getHipparcosSubset(upcStars);
    List<UpcStar> unmatchedStars = UpcUtils.getUnmatchedSubset(upcStars);

    upcStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(upcStars);
    hipStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(hipStars);
    unmatchedStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(unmatchedStars);

    logger.info("Loaded " + upcStarCrossMatches.size() + " UpcStars with SSA cross matches");
    logger.info("Loaded " + hipStarCrossMatches.size() + " UpcStars with Hipparcos and SSA cross matches");
    logger.info("Loaded " + unmatchedStarCrossMatches.size()
            + " UpcStars with no parallax cross-match, and with SSA cross matches");

    starsToPlot = upcStarCrossMatches;

    useHip = false;
    method = METHOD.NAIVE;
    fMax = 1.0;

    final JCheckBox plotAllCheckBox = new JCheckBox("Plot all UPC stars: ", true);
    plotAllCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (plotAllCheckBox.isSelected()) {
                starsToPlot = upcStarCrossMatches;
                updateChart();
            }
        }
    });

    final JCheckBox plotHipCheckBox = new JCheckBox("Plot Hipparcos stars only: ", false);
    plotHipCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (plotHipCheckBox.isSelected()) {
                starsToPlot = hipStarCrossMatches;
                updateChart();
            }
        }
    });

    final JCheckBox plotUnmatchedCheckBox = new JCheckBox("Plot all stars with no external match: ", false);
    plotUnmatchedCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (plotUnmatchedCheckBox.isSelected()) {
                starsToPlot = unmatchedStarCrossMatches;
                updateChart();
            }
        }
    });

    final ButtonGroup bg = new ButtonGroup();
    bg.add(plotHipCheckBox);
    bg.add(plotAllCheckBox);
    bg.add(plotUnmatchedCheckBox);

    JCheckBox useHipCheckBox = new JCheckBox("Use Hipparcos parallaxes when available", useHip);
    useHipCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            useHip = !useHip;
            updateChart();
        }
    });

    final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values());
    methodComboBox.setSelectedItem(method);
    methodComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            method = (METHOD) methodComboBox.getSelectedItem();
            updateChart();
        }
    });

    final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f");
    fSlider.setValue((int) Math.rint(100.0 * fMax));
    final JLabel fLabel = new JLabel(getFLabel());
    // Create a change listener fot these
    ChangeListener cl = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();

            if (source == fSlider) {
                // Compute fractional parallax error from slider position
                double newF = (2.0 * source.getValue() / 100.0);
                fMax = newF;
                fLabel.setText(getFLabel());
            }
            updateChart();
        }
    };
    fSlider.addChangeListener(cl);
    // Add a bit of padding to space things out
    fSlider.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Present controls below the HR diagram
    JPanel controls = new JPanel(new GridLayout(3, 3));
    controls.add(plotAllCheckBox);
    controls.add(plotHipCheckBox);
    controls.add(plotUnmatchedCheckBox);
    controls.add(new JLabel("Distance estimation method:"));
    controls.add(methodComboBox);
    controls.add(useHipCheckBox);
    controls.add(fLabel);
    controls.add(fSlider);

    // Initialise the ChartPanel
    updateChart();

    // Build the panel contents
    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);
    add(controls, BorderLayout.SOUTH);
}

From source file:Simulator.java

private void init() {
    setSize(400, 400);//  w w w  .ja v  a  2  s  . co m

    treeMap = new JMapViewerTree("Zones");

    // Listen to the map viewer for user operations so components will
    // receive events and update
    map().addJMVListener(this);

    setLayout(new BorderLayout());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    JPanel panel = new JPanel(new BorderLayout());
    JPanel panelTop = new JPanel();
    JPanel panelBottom = new JPanel();
    JPanel helpPanel = new JPanel();

    mperpLabelName = new JLabel("Meters/Pixels: ");
    mperpLabelValue = new JLabel(String.format("%s", map().getMeterPerPixel()));

    zoomLabel = new JLabel("Zoom: ");
    zoomValue = new JLabel(String.format("%s", map().getZoom()));

    add(panel, BorderLayout.NORTH);
    add(helpPanel, BorderLayout.SOUTH);
    panel.add(panelTop, BorderLayout.NORTH);
    panel.add(panelBottom, BorderLayout.SOUTH);
    JLabel helpLabel = new JLabel(
            "Use right mouse button to move,\n " + "left double click or mouse wheel to zoom.");
    helpPanel.add(helpLabel);
    JButton button = new JButton("Fit GPS Markers");
    button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            map().setDisplayToFitMapMarkers();
        }
    });
    panelBottom.add(button);

    JButton openButton = new JButton("Open GPS File");
    openButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser openFileDlg = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");
            openFileDlg.setFileFilter(filter);

            if (openFileDlg.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                File file = openFileDlg.getSelectedFile();
                //This is where a real application would open the file.
                System.out.println("Opening: " + file.getAbsolutePath() + ".");
                plotPoints(file.getAbsolutePath());
            } else {
                System.out.println("Open command cancelled by user.");
            }

        }
    });
    panelBottom.add(openButton);

    final JCheckBox showMapMarker = new JCheckBox("Map markers visible");
    showMapMarker.setSelected(map().getMapMarkersVisible());
    showMapMarker.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            map().setMapMarkerVisible(showMapMarker.isSelected());
        }
    });
    panelBottom.add(showMapMarker);

    panelTop.add(zoomLabel);
    panelTop.add(zoomValue);
    panelTop.add(mperpLabelName);
    panelTop.add(mperpLabelValue);

    add(treeMap, BorderLayout.CENTER);
}