List of usage examples for javax.swing JCheckBox addChangeListener
public void addChangeListener(ChangeListener l)
ChangeListener
to the button. From source file:JCheckBoxChangeListener.java
public static void main(String args[]) { JFrame frame = new JFrame("Iconizing CheckBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox aCheckBox4 = new JCheckBox("Stuffed Crust"); // Define ChangeListener ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { AbstractButton abstractButton = (AbstractButton) changeEvent.getSource(); ButtonModel buttonModel = abstractButton.getModel(); boolean armed = buttonModel.isArmed(); boolean pressed = buttonModel.isPressed(); boolean selected = buttonModel.isSelected(); System.out.println("Changed: " + armed + "/" + pressed + "/" + selected); }//from w w w.ja v a 2 s.co m }; aCheckBox4.addChangeListener(changeListener); frame.add(aCheckBox4); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Selecting CheckBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox checkBox = new JCheckBox("A"); // Define ChangeListener ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { AbstractButton abstractButton = (AbstractButton) changeEvent.getSource(); ButtonModel buttonModel = abstractButton.getModel(); boolean armed = buttonModel.isArmed(); boolean pressed = buttonModel.isPressed(); boolean selected = buttonModel.isSelected(); System.out.println("Changed: " + armed + "/" + pressed + "/" + selected); }//from w w w . j a v a2 s. c om }; // Attach Listeners checkBox.addChangeListener(changeListener); checkBox.setMnemonic(KeyEvent.VK_S); frame.add(checkBox, BorderLayout.NORTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { final String DESELECTED_LABEL = "Deselected"; final String SELECTED_LABEL = "Selected"; JFrame frame = new JFrame("Selecting CheckBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox checkBox = new JCheckBox(DESELECTED_LABEL); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { AbstractButton abstractButton = (AbstractButton) actionEvent.getSource(); boolean selected = abstractButton.getModel().isSelected(); String newLabel = (selected ? SELECTED_LABEL : DESELECTED_LABEL); abstractButton.setText(newLabel); }/*w ww . j a v a 2s. c o m*/ }; ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { AbstractButton abstractButton = (AbstractButton) changeEvent.getSource(); ButtonModel buttonModel = abstractButton.getModel(); boolean armed = buttonModel.isArmed(); boolean pressed = buttonModel.isPressed(); boolean selected = buttonModel.isSelected(); System.out.println("Changed: " + armed + "/" + pressed + "/" + selected); } }; ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent itemEvent) { AbstractButton abstractButton = (AbstractButton) itemEvent.getSource(); Color foreground = abstractButton.getForeground(); Color background = abstractButton.getBackground(); int state = itemEvent.getStateChange(); if (state == ItemEvent.SELECTED) { abstractButton.setForeground(background); abstractButton.setBackground(foreground); } } }; checkBox.addActionListener(actionListener); checkBox.addChangeListener(changeListener); checkBox.addItemListener(itemListener); checkBox.setMnemonic(KeyEvent.VK_S); frame.add(checkBox, BorderLayout.NORTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:SelectingCheckBox.java
public static void main(String args[]) { JFrame frame = new JFrame("Selecting CheckBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox checkBox = new JCheckBox(DESELECTED_LABEL); // Define ActionListener ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { AbstractButton abstractButton = (AbstractButton) actionEvent.getSource(); boolean selected = abstractButton.getModel().isSelected(); String newLabel = (selected ? SELECTED_LABEL : DESELECTED_LABEL); abstractButton.setText(newLabel); }//from w w w. ja va 2s.c o m }; ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { AbstractButton abstractButton = (AbstractButton) changeEvent.getSource(); ButtonModel buttonModel = abstractButton.getModel(); boolean armed = buttonModel.isArmed(); boolean pressed = buttonModel.isPressed(); boolean selected = buttonModel.isSelected(); System.out.println("Changed: " + armed + "/" + pressed + "/" + selected); } }; ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent itemEvent) { AbstractButton abstractButton = (AbstractButton) itemEvent.getSource(); Color foreground = abstractButton.getForeground(); Color background = abstractButton.getBackground(); int state = itemEvent.getStateChange(); if (state == ItemEvent.SELECTED) { abstractButton.setForeground(background); abstractButton.setBackground(foreground); } } }; checkBox.addActionListener(actionListener); checkBox.addChangeListener(changeListener); checkBox.addItemListener(itemListener); checkBox.setMnemonic(KeyEvent.VK_S); Container contentPane = frame.getContentPane(); contentPane.add(checkBox, BorderLayout.NORTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:biomine.bmvis2.pipeline.KMedoidsHighlight.java
@Override public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) { Box ret = new Box(BoxLayout.X_AXIS); ret.add(new JLabel("k:")); final JSpinner spin = new JSpinner(new SpinnerNumberModel(3, 1, 1000, 1)); spin.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { setK(((Number) spin.getValue()).intValue()); v.settingsChanged(false);/*from w w w. ja v a 2 s. com*/ } }); ret.add(spin); final JCheckBox showClustersBox = new JCheckBox("Color clusters"); ret.add(showClustersBox); showClustersBox.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { showClusters = showClustersBox.isSelected(); v.settingsChanged(false); } }); return ret; }
From source file:caarray.client.test.gui.GuiMain.java
private void initializeTests() throws Exception { int index = 0; ApiFacade apiFacade = new FullApiFacade(); List<ConfigurableTestSuite> shortTests = TestMain.getShortTestSuites(apiFacade); List<ConfigurableTestSuite> longTests = TestMain.getLongTestSuites(apiFacade); List<ConfigurableTestSuite> testSuites = new ArrayList<ConfigurableTestSuite>(); runTests = new boolean[shortTests.size() + longTests.size()]; for (ConfigurableTestSuite test : shortTests) { JCheckBox box = new JCheckBox(test.getDisplayName()); box.addChangeListener(new SelectTestListener(index)); box.setSelected(true);//from www .j a va 2s. c o m testCheckBoxes.add(box); selectionPanel.add(box); testSuites.add(test); index++; } for (ConfigurableTestSuite test : longTests) { JCheckBox box = new JCheckBox(test.getDisplayName()); box.addChangeListener(new SelectTestListener(index)); box.setSelected(false); testCheckBoxes.add(box); selectionPanel.add(box); testSuites.add(test); index++; } testSuiteCollection.add(testSuites); apiFacades.add(apiFacade); }
From source file:com.intuit.tank.tools.script.ScriptFilterRunner.java
/** * @return/*from ww w. j av a 2s . com*/ */ private Component createContentPanel() { JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true); scriptEditorTA = new RSyntaxTextArea(); setSyntaxStyle(); RTextScrollPane sp = new RTextScrollPane(scriptEditorTA); pane.setTopComponent(sp); JScrollPane scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); JPanel panel = new JPanel(new BorderLayout()); output = new TextAreaOutputLogger(scrollPane, INITIAL_OUTPUT_CONTENT); output.setEditable(false); output.setAutoscrolls(true); output.setScrollContent(true); output.setWrapStyleWord(true); scrollPane.setViewportView(output); JToolBar toolBar = new JToolBar(); JButton clearBT = new JButton("Clear"); clearBT.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { output.setText(INITIAL_OUTPUT_CONTENT); } }); final JCheckBox scrollCB = new JCheckBox("Auto Scroll Content"); scrollCB.setSelected(true); scrollCB.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { output.setScrollContent(scrollCB.isSelected()); } }); toolBar.add(clearBT); toolBar.add(scrollCB); panel.add(toolBar, BorderLayout.NORTH); panel.add(scrollPane, BorderLayout.CENTER); pane.setBottomComponent(panel); pane.setDividerLocation(300); return pane; }
From source file:sim.util.media.chart.BoxPlotGenerator.java
protected void buildGlobalAttributes(LabelledList list) { // create the chart ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(false); ((CategoryPlot) (chart.getPlot())).setRangeGridlinePaint(new Color(200, 200, 200)); xLabel = new PropertyField() { public String newValue(String newValue) { setXAxisLabel(newValue);/*from w ww . j a v a 2s . co m*/ getChartPanel().repaint(); return newValue; } }; xLabel.setValue(getXAxisLabel()); list.add(new JLabel("X Label"), xLabel); yLabel = new PropertyField() { public String newValue(String newValue) { setYAxisLabel(newValue); getChartPanel().repaint(); return newValue; } }; yLabel.setValue(getYAxisLabel()); list.add(new JLabel("Y Label"), yLabel); yLog = new JCheckBox(); yLog.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (yLog.isSelected()) { LogarithmicAxis logAxis = new LogarithmicAxis(yLabel.getValue()); logAxis.setStrictValuesFlag(false); ((CategoryPlot) (chart.getPlot())).setRangeAxis(logAxis); } else ((CategoryPlot) (chart.getPlot())).setRangeAxis(new NumberAxis(yLabel.getValue())); } }); list.add(new JLabel("Y Log Axis"), yLog); final JCheckBox ygridlines = new JCheckBox(); ygridlines.setSelected(false); ItemListener il = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(true); } else { ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(false); } } }; ygridlines.addItemListener(il); // JFreeChart's Box Plots look awful when wide because the mean // circle is based on the width of the bar to the exclusion of all // else. So I've restricted the width to be no more than 0.4, and 0.1 // is the suggested default. final double INITIAL_WIDTH = 0.1; final double MAXIMUM_RATIONAL_WIDTH = 0.4; maximumWidthField = new NumberTextField(INITIAL_WIDTH, 2.0, 0) { public double newValue(double newValue) { if (newValue <= 0.0 || newValue > MAXIMUM_RATIONAL_WIDTH) newValue = currentValue; ((BoxAndWhiskerRenderer) (((CategoryPlot) (chart.getPlot())).getRenderer())) .setMaximumBarWidth(newValue); //update(); return newValue; } }; list.addLabelled("Max Width", maximumWidthField); Box box = Box.createHorizontalBox(); box.add(new JLabel(" Y")); box.add(ygridlines); box.add(Box.createGlue()); list.add(new JLabel("Y Grid Lines"), ygridlines); mean = new JCheckBox(); mean.setSelected(true); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot())) .getRenderer()); renderer.setMeanVisible(mean.isSelected()); } }; mean.addItemListener(il); median = new JCheckBox(); median.setSelected(true); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot())) .getRenderer()); renderer.setMedianVisible(median.isSelected()); } }; median.addItemListener(il); list.add(new JLabel("Mean"), mean); list.add(new JLabel("Median"), median); final JCheckBox horizontal = new JCheckBox(); horizontal.setSelected(false); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { CategoryPlot plot = (CategoryPlot) (chart.getPlot()); if (e.getStateChange() == ItemEvent.SELECTED) { plot.setOrientation(PlotOrientation.HORIZONTAL); } else { plot.setOrientation(PlotOrientation.VERTICAL); } //updateGridLines(); } }; horizontal.addItemListener(il); list.add(new JLabel("Horizontal"), horizontal); final JCheckBox whiskersUseFillColorButton = new JCheckBox(); whiskersUseFillColorButton.setSelected(false); whiskersUseFillColorButton.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot())) .getRenderer()); renderer.setUseOutlinePaintForWhiskers(!whiskersUseFillColorButton.isSelected()); } }); box = Box.createHorizontalBox(); box.add(new JLabel(" Colored")); box.add(whiskersUseFillColorButton); box.add(Box.createGlue()); list.add(new JLabel("Whiskers"), box); }
From source file:edu.gmu.cs.sim.util.media.chart.BoxPlotGenerator.java
protected void buildGlobalAttributes(LabelledList list) { // create the chart ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(false); ((CategoryPlot) (chart.getPlot())).setRangeGridlinePaint(new Color(200, 200, 200)); xLabel = new PropertyField() { public String newValue(String newValue) { setXAxisLabel(newValue);// www . j a v a 2 s. c om getChartPanel().repaint(); return newValue; } }; xLabel.setValue(getXAxisLabel()); list.add(new JLabel("X Label"), xLabel); yLabel = new PropertyField() { public String newValue(String newValue) { setYAxisLabel(newValue); getChartPanel().repaint(); return newValue; } }; yLabel.setValue(getYAxisLabel()); list.add(new JLabel("Y Label"), yLabel); yLog = new JCheckBox(); yLog.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (yLog.isSelected()) { LogarithmicAxis logAxis = new LogarithmicAxis(yLabel.getValue()); logAxis.setStrictValuesFlag(false); ((CategoryPlot) (chart.getPlot())).setRangeAxis(logAxis); } else { ((CategoryPlot) (chart.getPlot())).setRangeAxis(new NumberAxis(yLabel.getValue())); } } }); list.add(new JLabel("Y Log Axis"), yLog); final JCheckBox ygridlines = new JCheckBox(); ygridlines.setSelected(false); ItemListener il = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(true); } else { ((CategoryPlot) (chart.getPlot())).setRangeGridlinesVisible(false); } } }; ygridlines.addItemListener(il); // JFreeChart's Box Plots look awful when wide because the mean // circle is based on the width of the bar to the exclusion of all // else. So I've restricted the width to be no more than 0.4, and 0.1 // is the suggested default. final double INITIAL_WIDTH = 0.1; final double MAXIMUM_RATIONAL_WIDTH = 0.4; maximumWidthField = new NumberTextField(INITIAL_WIDTH, 2.0, 0) { public double newValue(double newValue) { if (newValue <= 0.0 || newValue > MAXIMUM_RATIONAL_WIDTH) { newValue = currentValue; } ((BoxAndWhiskerRenderer) (((CategoryPlot) (chart.getPlot())).getRenderer())) .setMaximumBarWidth(newValue); //update(); return newValue; } }; list.addLabelled("Max Width", maximumWidthField); Box box = Box.createHorizontalBox(); box.add(new JLabel(" Y")); box.add(ygridlines); box.add(Box.createGlue()); list.add(new JLabel("Y Grid Lines"), ygridlines); mean = new JCheckBox(); mean.setSelected(true); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot())) .getRenderer()); renderer.setMeanVisible(mean.isSelected()); } }; mean.addItemListener(il); median = new JCheckBox(); median.setSelected(true); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot())) .getRenderer()); renderer.setMedianVisible(median.isSelected()); } }; median.addItemListener(il); list.add(new JLabel("Mean"), mean); list.add(new JLabel("Median"), median); final JCheckBox horizontal = new JCheckBox(); horizontal.setSelected(false); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { CategoryPlot plot = (CategoryPlot) (chart.getPlot()); if (e.getStateChange() == ItemEvent.SELECTED) { plot.setOrientation(PlotOrientation.HORIZONTAL); } else { plot.setOrientation(PlotOrientation.VERTICAL); } //updateGridLines(); } }; horizontal.addItemListener(il); list.add(new JLabel("Horizontal"), horizontal); final JCheckBox whiskersUseFillColorButton = new JCheckBox(); whiskersUseFillColorButton.setSelected(false); whiskersUseFillColorButton.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { BoxAndWhiskerRenderer renderer = ((BoxAndWhiskerRenderer) ((CategoryPlot) (chart.getPlot())) .getRenderer()); renderer.setUseOutlinePaintForWhiskers(!whiskersUseFillColorButton.isSelected()); } }); box = Box.createHorizontalBox(); box.add(new JLabel(" Colored")); box.add(whiskersUseFillColorButton); box.add(Box.createGlue()); list.add(new JLabel("Whiskers"), box); }
From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptComponent.java
/** * Returns the children associated to that component. * //from ww w . j av a2 s .c o m * @param children The value to set. */ void setChildren(List<ScriptComponent> children) { this.children = children; if (component instanceof JCheckBox) { JCheckBox box = (JCheckBox) component; box.addChangeListener(this); Iterator<ScriptComponent> i = children.iterator(); while (i.hasNext()) i.next().setParent(this); } handleSelection(); }