List of usage examples for javax.swing JComboBox removeActionListener
public void removeActionListener(ActionListener l)
ActionListener
. 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); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("Command: " + actionEvent.getActionCommand()); ItemSelectable is = (ItemSelectable) actionEvent.getSource(); System.out.println(", Selected: " + selectedString(is)); }//from w w w . j ava 2 s . com }; comboBox.addActionListener(actionListener); comboBox.removeActionListener(actionListener); frame.setSize(400, 200); frame.setVisible(true); }
From source file:com.demonwav.mcdev.platform.mcp.version.McpVersion.java
public void setMcpVersion(JComboBox<McpVersionEntry> mcpVersionBox, String version, ActionListener actionListener) { mcpVersionBox.removeActionListener(actionListener); mcpVersionBox.removeAllItems();//from ww w . j a v a2s.co m final Pair<List<Integer>, List<Integer>> stable = getStable(version); stable.getFirst().stream().sorted((one, two) -> one.compareTo(two) * -1) .map(s -> new McpVersionEntry("stable_" + s)).forEach(mcpVersionBox::addItem); final Pair<List<Integer>, List<Integer>> snapshot = getSnapshot(version); snapshot.getFirst().stream().sorted((one, two) -> one.compareTo(two) * -1) .map(s -> new McpVersionEntry("snapshot_" + s)).forEach(mcpVersionBox::addItem); // The "seconds" in the pairs are bad, but still available to the user // We will color them read stable.getSecond().stream().sorted((one, two) -> one.compareTo(two) * -1) .map(s -> new McpVersionEntry("stable_" + s, true)).forEach(mcpVersionBox::addItem); snapshot.getSecond().stream().sorted((one, two) -> one.compareTo(two) * -1) .map(s -> new McpVersionEntry("snapshot_" + s, true)).forEach(mcpVersionBox::addItem); mcpVersionBox.addActionListener(actionListener); }
From source file:grafix.telas.TelaComparativos.java
private void removerListener(JComboBox combo) { try {/*from w w w. j a v a 2 s. co m*/ combo.removeActionListener(combo.getActionListeners()[0]); } catch (Exception e) { } }
From source file:de.mprengemann.intellij.plugin.androidicons.dialogs.IconImporter.java
private void prepareSpinner(JComboBox comboBox, ActionListener listener) { comboBox.removeActionListener(listener); comboBox.setSelectedItem(null);//w w w . ja v a 2 s . c om comboBox.removeAllItems(); }
From source file:com.game.ui.views.PlayerEditor.java
@Override public void actionPerformed(ActionEvent ae) { validationMess.setText(""); validationMess.setVisible(false);//from ww w. j a va 2s .co m if (ae.getActionCommand().equalsIgnoreCase("dropDown")) { JComboBox comboBox = (JComboBox) ae.getSource(); String type = comboBox.getSelectedItem().toString(); for (GameCharacter user : GameBean.playerDetails) { Player player = (Player) user; if (player.getType().equalsIgnoreCase(type)) { ((JTextField) leftPanel.getComponent(2)).setText(player.getName()); ((JTextField) leftPanel.getComponent(4)).setText(player.getImagePath()); ((JTextField) leftPanel.getComponent(6)).setText(new Integer(player.getHealth()).toString()); ((JTextField) leftPanel.getComponent(8)).setText(new Integer(player.getAttackPts()).toString()); ((JTextField) leftPanel.getComponent(10)).setText(new Integer(player.getArmor()).toString()); ((JTextField) leftPanel.getComponent(12)) .setText(new Integer(player.getAttackRange()).toString()); ((JTextField) leftPanel.getComponent(14)).setText(new Integer(player.getMovement()).toString()); ((JTextField) leftPanel.getComponent(16)).setText(player.getType()); JComboBox cBox = (JComboBox) leftPanel.getComponent(18); cBox.setSelectedItem(player.getInventory().getEquippedWeapon().getName()); lvlPanel.txtFields[0].setText("" + player.getLevel()); lvlPanel.txtFields[1].setText("" + player.getExp()); lvlPanel.txtFields[2].setText("" + player.getStrength()); lvlPanel.txtFields[3].setText("" + player.getVitality()); lvlPanel.txtFields[4].setText("" + player.getDexterity()); lvlPanel.txtFields[5].setText("" + player.getWisdom()); break; // return; } } } else { String name = ((JTextField) leftPanel.getComponent(2)).getText(); String image = ((JTextField) leftPanel.getComponent(4)).getText(); String health = ((JTextField) leftPanel.getComponent(6)).getText(); String attackPts = ((JTextField) leftPanel.getComponent(8)).getText(); String armourPts = ((JTextField) leftPanel.getComponent(10)).getText(); String attackRnge = ((JTextField) leftPanel.getComponent(12)).getText(); String movement = ((JTextField) leftPanel.getComponent(14)).getText(); String type = ((JTextField) leftPanel.getComponent(16)).getText(); String weapon = ((JComboBox) leftPanel.getComponent(18)).getSelectedItem().toString(); int attr[] = new int[6]; attr[0] = Integer.parseInt(lvlPanel.txtFields[0].getText()); attr[1] = Integer.parseInt(lvlPanel.txtFields[1].getText()); attr[2] = Integer.parseInt(lvlPanel.txtFields[2].getText()); attr[3] = Integer.parseInt(lvlPanel.txtFields[3].getText()); attr[4] = Integer.parseInt(lvlPanel.txtFields[4].getText()); attr[5] = Integer.parseInt(lvlPanel.txtFields[5].getText()); // validationMess.setText(""); // validationMess.setVisible(false); if (StringUtils.isNotBlank(image) && StringUtils.isNotBlank(health) && StringUtils.isNotBlank(attackPts) && StringUtils.isNotBlank(armourPts) && StringUtils.isNotBlank(attackRnge) && StringUtils.isNotBlank(movement) && StringUtils.isNotBlank(type) && StringUtils.isNotBlank(weapon)) { validationMess.setVisible(false); Player player = new Player(); //have to remove the following statement later.. player.setName(name); player.setAttackPts(Integer.parseInt(attackPts)); player.setAttackRange(Integer.parseInt(attackRnge)); player.setHealth(Integer.parseInt(health)); player.setImagePath(image); player.setMovement(Integer.parseInt(movement)); player.setArmor(Integer.parseInt(armourPts)); player.setType(type); Inventory inventory = new Inventory(); int position = GameUtils.getPositionOfWeaponItem(weapon); Weapon weaponObj = (Weapon) GameBean.weaponDetails.get(position); inventory.setEquippedWeapon(weaponObj); player.setInventory(inventory); player.setLevel(attr[0]); player.setExp(attr[1]); player.setStrength(attr[2]); player.setVitality(attr[3]); player.setDexterity(attr[4]); player.setWisdom(attr[5]); boolean characterAlrdyPresent = false; for (int i = 0; i < GameBean.playerDetails.size(); i++) { Player charFromList = (Player) GameBean.playerDetails.get(i); if (charFromList.getType().equalsIgnoreCase(type)) { GameBean.playerDetails.remove(i); characterAlrdyPresent = true; } } GameBean.playerDetails.add(player); try { GameUtils.writeCharactersToXML(GameBean.playerDetails, Configuration.PATH_FOR_USER_CHARACTERS); validationMess.setText("Saved Successfully.."); validationMess.setVisible(true); if (!characterAlrdyPresent) { comboBox.addItem(type); comboBox.removeActionListener(this); comboBox.setSelectedItem(type); comboBox.addActionListener(this); } } catch (Exception e) { System.out.println("PlayerEditor : actionPerformed() : Some error occured " + e); validationMess.setText("Some error occured.."); validationMess.setVisible(true); e.printStackTrace(); } } else { validationMess.setText("Pls enter all the fields or pls choose a character from the drop down"); validationMess.setVisible(true); } } this.revalidate(); // JFrame frame = (JFrame)SwingUtilities.getAncestorNamed("Frame", this); // frame.revalidate(); }