public void addActionListener(ActionListener action) { if (selector != null) { ActionListener[] actions = selector.getActionListeners(); for (ActionListener a : actions) selector.removeActionListener(a); selector.addActionListener(action); for (ActionListener a : actions) selector.addActionListener(a); } }
public static void comboSeleccionarSinEvento(JComboBox combo, Object o) { ActionListener[] actionListeners = combo.getActionListeners(); for (ActionListener al : actionListeners) { combo.removeActionListener(al); } combo.setSelectedItem(o); for (ActionListener al : actionListeners) { combo.addActionListener(al); } }
// This method is called when a cell value is edited by the user. @Override public Component getTableCellEditorComponent( JTable table, Object value, boolean isSelected, int rowIndex, int colIndex) { DeviceControlTableModel data = (DeviceControlTableModel) table.getModel(); item_ = data.getPropertyItem(rowIndex); // Configure the component with the specified value: if (item_.allowed.length == 0) { if (item_.hasRange) { if (item_.isInteger()) { slider_.setLimits((int) item_.lowerLimit, (int) item_.upperLimit); } else { slider_.setLimits(item_.lowerLimit, item_.upperLimit); } try { slider_.setText((String) value); } catch (ParseException ex) { Log.log(ex); } return slider_; } else { text_.setText((String) value); return text_; } } else { ActionListener[] l = combo_.getActionListeners(); for (int i = 0; i < l.length; i++) { combo_.removeActionListener(l[i]); } combo_.removeAllItems(); for (int i = 0; i < item_.allowed.length; i++) { combo_.addItem(item_.allowed[i]); } combo_.setSelectedItem(item_.value); // end editing on selection change combo_.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fireEditingStopped(); } }); return combo_; } }
private void drawLevelOfDifficulty() { // Create the combo box, select the item at index 4. JLabel info_ = new JLabel(); info_.setOpaque(true); info_.setBackground(new Color(127, 127, 127)); info_.setForeground(Color.ORANGE); info_.setText(" Schwierigkeitsgrad "); info_.setBounds(290, 5, 350, 28); if (level_handler_ != null) { final LinkedList level_name_list_ = level_handler_.getLevelNameList(); String[] level_list_ = new String[level_name_list_.size()]; int tmp = 1; for (int count = 1; count < level_name_list_.size() + 1; count++) { level_list_[count - 1] = (String) level_name_list_.get(count - 1); if (current_selected_ == count) { tmp = count - 1; } } final JComboBox level_of_difficulty_ = new JComboBox(level_list_); level_of_difficulty_.setBounds(465, 8, 155, 20); this.add(level_of_difficulty_); this.add(info_); level_of_difficulty_.setSelectedIndex(tmp); if (level_of_difficulty_.getActionListeners().length == 0) { level_of_difficulty_.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { // Load // rules // button // pressed JComboBox cb = (JComboBox) evt.getSource(); String name = (String) cb.getSelectedItem(); current_selected_ = cb.getSelectedIndex() + 1; simulation_control_.drawNewLabyrinth(current_selected_); } }); } } }
/** Sets the labels according to current locale */ public void setLabels() { regressionLabels = new String[Regression.values().length]; setRegressionLabels(); // we need to remove old labels from combobox and we don't want the // listener to // be operational since it will call unnecessary Construction updates int j = cbRegression.getSelectedIndex(); ActionListener al = cbRegression.getActionListeners()[0]; cbRegression.removeActionListener(al); cbRegression.removeAllItems(); for (int i = 0; i < regressionLabels.length; i++) { cbRegression.addItem(regressionLabels[i]); } cbRegression.setSelectedIndex(j); cbRegression.addActionListener(al); ((TitledBorder) regressionPanel.getBorder()).setTitle(app.getMenu("RegressionModel")); lblEqn.setText(app.getMenu("Equation") + ":"); lblEvaluate.setText(app.getMenu("Evaluate") + ": "); }