List of usage examples for java.awt.event ItemListener ItemListener
ItemListener
From source file:TextBouncer.java
public static void main(String[] args) { String s = "Java Source and Support"; final int size = 64; if (args.length > 0) s = args[0];/*from w ww.ja v a 2 s. co m*/ Panel controls = new Panel(); final Choice choice = new Choice(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Font[] allFonts = ge.getAllFonts(); for (int i = 0; i < allFonts.length; i++) choice.addItem(allFonts[i].getName()); Font defaultFont = new Font(allFonts[0].getName(), Font.PLAIN, size); final TextBouncer bouncer = new TextBouncer(s, defaultFont); Frame f = new AnimationFrame(bouncer); f.setFont(new Font("Serif", Font.PLAIN, 12)); controls.add(bouncer.createCheckbox("Antialiasing", TextBouncer.ANTIALIASING)); controls.add(bouncer.createCheckbox("Gradient", TextBouncer.GRADIENT)); controls.add(bouncer.createCheckbox("Shear", TextBouncer.SHEAR)); controls.add(bouncer.createCheckbox("Rotate", TextBouncer.ROTATE)); controls.add(bouncer.createCheckbox("Axes", TextBouncer.AXES)); Panel fontControls = new Panel(); choice.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { Font font = new Font(choice.getSelectedItem(), Font.PLAIN, size); bouncer.setFont(font); } }); fontControls.add(choice); Panel allControls = new Panel(new GridLayout(2, 1)); allControls.add(controls); allControls.add(fontControls); f.add(allControls, BorderLayout.NORTH); f.setSize(300, 300); f.setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); check.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { System.out.println("Checked? " + check.isSelected()); }/*from w ww . ja v a2s .c o m*/ }); getContentPane().add(check); pack(); setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("Checkable"); bar.add(menu);//from w w w . ja v a 2s . c om menu.add(check); check.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { System.out.println("Checked? " + check.isSelected()); } }); setJMenuBar(bar); getContentPane().add(new JLabel("A placeholder")); pack(); setSize(300, 300); setVisible(true); }
From source file:RemoveListener.java
public RemoveListener() { JPanel panel = new JPanel(); active.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { if (active.isSelected()) { add.addActionListener(buttonlistener); } else { add.removeActionListener(buttonlistener); }/*from w ww . j ava 2 s .c o m*/ } }); panel.add(add); panel.add(active); JFrame f = new JFrame(); f.add(panel); f.setSize(310, 200); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:Main.java
Main() { JFrame jfrm = new JFrame("Check Box Demo"); jfrm.setLayout(new FlowLayout()); jfrm.setSize(300, 200);/* www. j a va 2 s. c om*/ jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jcbOption1.setEnabled(false); jcbOption2.setEnabled(false); jcbOption3.setEnabled(false); jcbControl.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { if (jcbControl.isSelected()) { jcbOption1.setEnabled(true); jcbOption2.setEnabled(true); jcbOption3.setEnabled(true); System.out.println("enabled."); } else { jcbOption1.setEnabled(false); jcbOption2.setEnabled(false); jcbOption3.setEnabled(false); System.out.println("disabled."); } } }); jcbOption1.addItemListener(this); jcbOption2.addItemListener(this); jcbOption3.addItemListener(this); jfrm.add(jcbControl); jfrm.add(jcbOption1); jfrm.add(jcbOption2); jfrm.add(jcbOption3); jfrm.setVisible(true); }
From source file:ToggleButtonCheckBoxRadioButton.java
public TogglePanel() { JToggleButton tog = new JToggleButton("Toggle"); ItemListener listener = new ItemListener() { public void itemStateChanged(ItemEvent e) { AbstractButton src = (AbstractButton) (e.getSource()); System.out.println("Toggle: " + src.getText()); }/*from www.j a v a 2 s. c o m*/ }; tog.addItemListener(listener); add(tog); JCheckBox cbox = new JCheckBox("Checkbox"); cbox.addItemListener(listener); add(cbox); ButtonGroup btngroup = new ButtonGroup(); for (int i = 1; i <= 3; i++) { JRadioButton radio = new JRadioButton("Radio " + i); btngroup.add(radio); radio.addItemListener(listener); add(radio); } }
From source file:ComboBoxWithItemChangedListener.java
public ComboPanel() { final JComboBox combo = new JComboBox(treasure); combo.setMaximumRowCount(5);/* www .j a v a2 s . co m*/ combo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { System.out.println("Combo: " + combo.getSelectedItem()); } }); combo.setSelectedIndex(4); add(combo); }
From source file:CombiningShapes.java
public CombiningShapes() { mShapeOne = new Ellipse2D.Double(40, 20, 80, 80); mShapeTwo = new Rectangle2D.Double(60, 40, 80, 80); setBackground(Color.white);// w w w . j a v a 2 s.c om setLayout(new BorderLayout()); JPanel controls = new JPanel(); mOptions = new JComboBox(new String[] { "outline", "add", "intersection", "subtract", "exclusive or" }); mOptions.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { repaint(); } }); controls.add(mOptions); add(controls, BorderLayout.SOUTH); }
From source file:hr.fer.zemris.vhdllab.platform.ui.wizard.support.FileForm.java
@Override protected void doBuildForm(TableFormBuilder builder) { projectCombobox = (JComboBox) builder.add("project")[1]; projectCombobox.addItemListener(new ItemListener() { @Override//from w ww .jav a 2 s .co m public void itemStateChanged(ItemEvent e) { getFormModel().validate(); } }); builder.row(); focusOnBeginning(builder.add("name")[1]); }
From source file:org.pentaho.ui.xul.swing.tags.SwingCheckbox.java
public SwingCheckbox(Element self, XulComponent parent, XulDomContainer domContainer, String tagName) { super("checkbox"); checkBox = new JCheckBox(); checkBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { SwingCheckbox.this.changeSupport.firePropertyChange("checked", null, ((JCheckBox) e.getSource()).isSelected()); }// w ww .j ava 2 s .c om }); setManagedObject(checkBox); }