List of usage examples for java.awt.event ItemEvent getItemSelectable
public ItemSelectable getItemSelectable()
From source file:Main.java
public static void main(final String args[]) { final String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Selecting JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox comboBox = new JComboBox(labels); frame.add(comboBox, BorderLayout.SOUTH); ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent itemEvent) { int state = itemEvent.getStateChange(); String stateString = ((state == ItemEvent.SELECTED) ? "Selected" : "Deselected"); System.out.println("Item: " + itemEvent.getItem()); System.out.println(", State: " + stateString); ItemSelectable is = itemEvent.getItemSelectable(); System.out.println(", Selected: " + selectedString(is)); }//from w w w .j a va2 s . com }; comboBox.addItemListener(itemListener); frame.setSize(400, 200); frame.setVisible(true); }
From source file:SelectingComboSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "J", "I" }; JFrame frame = new JFrame("Selecting JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JComboBox comboBox = new JComboBox(labels); contentPane.add(comboBox, BorderLayout.SOUTH); final JTextArea textArea = new JTextArea(); textArea.setEditable(false);/*from w w w. j ava 2 s . co m*/ JScrollPane sp = new JScrollPane(textArea); contentPane.add(sp, BorderLayout.CENTER); ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent itemEvent) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); int state = itemEvent.getStateChange(); String stateString = ((state == ItemEvent.SELECTED) ? "Selected" : "Deselected"); pw.print("Item: " + itemEvent.getItem()); pw.print(", State: " + stateString); ItemSelectable is = itemEvent.getItemSelectable(); pw.print(", Selected: " + selectedString(is)); pw.println(); textArea.append(sw.toString()); } }; comboBox.addItemListener(itemListener); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.print("Command: " + actionEvent.getActionCommand()); ItemSelectable is = (ItemSelectable) actionEvent.getSource(); pw.print(", Selected: " + selectedString(is)); pw.println(); textArea.append(sw.toString()); } }; comboBox.addActionListener(actionListener); frame.setSize(400, 200); frame.setVisible(true); }
From source file:ItemEventComponent.java
public void itemStateChanged(ItemEvent e) { Object[] o = e.getItemSelectable().getSelectedObjects(); Integer i = (Integer) o[0]; System.out.println(i);/*from w w w .j a va2 s . c o m*/ }
From source file:CheckBoxDemo.java
/** Listens to the check boxes. */ public void itemStateChanged(ItemEvent e) { int index = 0; char c = '-'; Object source = e.getItemSelectable(); if (source == chinButton) { index = 0;//from w w w. jav a 2 s. c o m c = 'c'; } else if (source == glassesButton) { index = 1; c = 'g'; } else if (source == hairButton) { index = 2; c = 'h'; } else if (source == teethButton) { index = 3; c = 't'; } // Now that we know which button was pushed, find out // whether it was selected or deselected. if (e.getStateChange() == ItemEvent.DESELECTED) { c = '-'; } // Apply the change to the string. choices.setCharAt(index, c); updatePicture(); }
From source file:SwingCheckBoxDemo.java
/** Listens to the check boxes. */ public void itemStateChanged(ItemEvent e) { int index = 0; char c = '-'; Object source = e.getItemSelectable(); if (source == chinButton) { index = 0;// w ww . java2s .co m c = 'c'; } else if (source == glassesButton) { index = 1; c = 'g'; } else if (source == hairButton) { index = 2; c = 'h'; } else if (source == teethButton) { index = 3; c = 't'; } //Now that we know which button was pushed, find out //whether it was selected or deselected. if (e.getStateChange() == ItemEvent.DESELECTED) { c = '-'; } //Apply the change to the string. choices.setCharAt(index, c); updatePicture(); }
From source file:SplineAnim.java
public void itemStateChanged(ItemEvent event) { Object source = event.getSource(); ItemSelectable ie = event.getItemSelectable(); if (source == interpChoice) { try {//www . ja v a2 s . c o m if (ie.getSelectedObjects()[0] == "Spline") { linear = false; } if (ie.getSelectedObjects()[0] == "Linear") { linear = true; } startInterpolator(); } catch (Exception e) { System.err.println("Exception " + e); } } }
From source file:net.sf.taverna.t2.activities.wsdlsir.views.WSDLActivityConfigurationView.java
/** * Disable/enable items on the panel based on this radio button * has been selected.//from ww w . j av a 2s . c o m */ public void itemStateChanged(ItemEvent e) { Object source = e.getItemSelectable(); //first disable all noSecurityLabel.setEnabled(false); httpSecurityAuthNLabel.setEnabled(false); SAMLSecurityAuthNLabel.setEnabled(false); wsSecurityAuthNLabel.setEnabled(false); passwordTypeComboBox.setEnabled(false); setHttpUsernamePasswordButton.setEnabled(false); setWsdlUsernamePasswordButton.setEnabled(false); addTimestampCheckBox.setEnabled(false); setSAMLGETCookieButton.setEnabled(false); //then enable the selected if (source == noSecurityRadioButton) { noSecurityLabel.setEnabled(true); } else if (source == httpSecurityAuthNRadioButton) { httpSecurityAuthNLabel.setEnabled(true); setHttpUsernamePasswordButton.setEnabled(true); } else if (source == SAMLSecurityAuthNRadioButton) { SAMLSecurityAuthNLabel.setEnabled(true); setSAMLGETCookieButton.setEnabled(true); } else if (source == wsSecurityAuthNRadioButton) { wsSecurityAuthNLabel.setEnabled(true); passwordTypeComboBox.setEnabled(true); setWsdlUsernamePasswordButton.setEnabled(true); addTimestampCheckBox.setEnabled(true); } }
From source file:mesquite.zephyr.lib.RAxMLRunner.java
public void itemStateChanged(ItemEvent e) { if (e.getItemSelectable() == doBootstrapCheckbox) { checkEnabled(doBootstrapCheckbox.getState()); } else if (e.getItemSelectable() == constraintButtons && constraintButtons.getValue() > 0) { getConstraintTreeSource();/*ww w .java 2 s . c o m*/ } }
From source file:mesquite.zephyr.lib.GarliRunner.java
public void itemStateChanged(ItemEvent e) { if (charPartitionButtons.isAButton(e.getItemSelectable())) { // button for the partition scheme processCharacterModels();/*from w w w . j a va2s . com*/ if (charPartitionButtons != null) partitionScheme = charPartitionButtons.getValue(); if (partitionChoice != null) preparePartitionChoice(partitionChoice, partitionScheme); } else if (e.getItemSelectable() == partitionChoice) { // popup for which partition to edit processCharacterModels(); if (partitionScheme == partitionByCodonPosition) { if (codpos1Subset.equalsIgnoreCase((String) e.getItem())) { currentPartitionSubset = 0; setCharacterModels(); } else if (codpos2Subset.equalsIgnoreCase((String) e.getItem())) { currentPartitionSubset = 1; setCharacterModels(); } else if (codpos3Subset.equalsIgnoreCase((String) e.getItem())) { currentPartitionSubset = 2; setCharacterModels(); } else if (nonCodingSubset.equalsIgnoreCase((String) e.getItem())) { currentPartitionSubset = 3; setCharacterModels(); } } else if (partitionScheme == partitionByCharacterGroups) { currentPartitionSubset = ZephyrUtil.getPartitionSubset(data, (String) e.getItem()); setCharacterModels(); } else setCharacterModels(); } else if (e.getItemSelectable() == constraintButtons && constraintButtons.getValue() > 0) { getConstraintTreeSource(); } else if (e.getItemSelectable() == rateMatrixChoice) { if (data instanceof ProteinData) { } else { String matrix = ""; int choiceValue = rateMatrixChoice.getSelectedIndex(); switch (choiceValue) { case 0: matrix = "1rate"; break; case 1: matrix = "2rate"; break; case 2: matrix = "6rate"; break; case 3: // Custom if (customMatrix != null) { matrix = customMatrix.getText(); if (matrix == null || "1rate 2rate 6rate".indexOf(matrix) >= 0) // Debugg.println keep previous custom matrices remembered for users who switch back to them? matrix = "(a a a a a a)"; } break; default: matrix = "6rate"; } if (customMatrix != null) { customMatrix.setText(matrix); if (choiceValue == 3) { customMatrix.setEditable(true); customMatrix.setBackground(Color.white); } else { customMatrix.setEditable(false); customMatrix.setBackground(ColorDistribution.veryLightGray); } } } } else if (e.getItemSelectable() == doBootstrapCheckbox) { checkEnabled(doBootstrapCheckbox.getState()); } }
From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java
/** * Checkbox hat sich verndert// ww w. ja v a2 s .co m */ @Override public void itemStateChanged(ItemEvent ev) { if (ignoreAction) return; // //////////////////////////////////////////////////////////////////////// // Checkbox Event? if (ev.getSource() instanceof JCheckBox) { JCheckBox cb = (JCheckBox) ev.getItemSelectable(); String cmd = cb.getActionCommand(); // ////////////////////////////////////////////////////////////////////// // Dynamische Gradienten? if (cmd.equals("dyn_gradients_on")) { lg.debug("dynamic gradients <" + cb.isSelected() + ">"); currentConfig.setDynGradientsEnable(cb.isSelected()); } // ////////////////////////////////////////////////////////////////////// // Deepstops else if (cmd.equals("deepstops_on")) { lg.debug("depstops <" + cb.isSelected() + ">"); currentConfig.setDeepStopEnable(cb.isSelected()); } // ////////////////////////////////////////////////////////////////////// // Passive Semiclose Rebreather Mode? else if (cmd.equals("individuals_pscr_on")) { lg.debug("pscr mode <" + cb.isSelected() + ">"); currentConfig.setPscrModeEnabled(cb.isSelected()); } // ////////////////////////////////////////////////////////////////////// // Sensor warning on/off else if (cmd.equals("individual_sensors_on")) { lg.debug("sensors on <" + cb.isSelected() + ">"); currentConfig.setSensorsEnabled(cb.isSelected()); } // ////////////////////////////////////////////////////////////////////// // Warnungen an/aus else if (cmd.equals("individuals_warnings_on")) { lg.debug("warnings on <" + cb.isSelected() + ">"); currentConfig.setSountEnabled(cb.isSelected()); } else { lg.warn("unknown item changed: <" + cb.getActionCommand() + "> <" + cb.isSelected() + ">"); } } }