List of usage examples for javax.swing JComboBox getSelectedItem
public Object getSelectedItem()
From source file:carfuzzy.Operations.java
public double getMembership(JComboBox s, int input) { double membership; if (s.getSelectedIndex() == 0) { //veryslow ya da veryclose ise(left Trapezoid) if (s.getSelectedItem().getClass() == Speed.class) { speed = (Speed) s.getSelectedItem(); membership = leftTrapezoidalMembership(input, speed.getValue()); return membership; } else {//w ww . j a v a 2 s . c o m distance = (Distance) s.getSelectedItem(); membership = leftTrapezoidalMembership(input, distance.getValue()); return membership; } } else if (s.getSelectedIndex() == s.getItemCount() - 1) { //veryfast ya da away ise(right Trapezoid) if (s.getSelectedItem().getClass() == Speed.class) { speed = (Speed) s.getSelectedItem(); membership = rightTrapezoidalMembership(input, speed.getValue()); return membership; } else { distance = (Distance) s.getSelectedItem(); membership = rightTrapezoidalMembership(input, distance.getValue()); return membership; } } else { // Triangular ise if (s.getSelectedItem().getClass() == Speed.class) { speed = (Speed) s.getSelectedItem(); membership = triangularMembership(input, speed.getValue()); return membership; } else { distance = (Distance) s.getSelectedItem(); membership = triangularMembership(input, distance.getValue()); return membership; } } }
From source file:com.game.ui.views.PlayerEditor.java
@Override public void actionPerformed(ActionEvent ae) { validationMess.setText(""); validationMess.setVisible(false);/*from w ww . j a v a2s .c o 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(); }
From source file:Main.java
private JPanel createComboLabelPanel(int index, JComboBox<ComboColor> combo) { JPanel panel = new JPanel(); JLabel label = new JLabel(SIGNAL + " " + index); label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); label.setOpaque(true);/*www.j a v a 2 s. c o m*/ combo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { ComboColor cColor = (ComboColor) combo.getSelectedItem(); label.setBackground(cColor.getColor()); } }); panel.add(label); panel.add(combo); return panel; }
From source file:it.imtech.configuration.ChooseServer.java
/** * Creates new form ChooseServer/*ww w. ja v a2 s .c om*/ */ public ChooseServer(XMLConfiguration config) { initComponents(); bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); Server[] servers = getServersFromConfig(config, bundle); choose_server.setModel(new javax.swing.DefaultComboBoxModel(servers)); choose_server.setSelectedItem(servers[0]); choose_server.setMinimumSize(new Dimension(400, 20)); getLanguagesFromConfig(config, bundle); choose_language.setModel(new javax.swing.DefaultComboBoxModel(Globals.LANGUAGES)); choose_language.setSelectedItem(this.selected_lang); choose_language.setMinimumSize(new Dimension(400, 20)); updateLanguage(); MigLayout choose_layout = new MigLayout("fillx, insets 10 20 10 50"); main_panel = new JPanel(choose_layout); main_panel.add(label_server_1, "wrap 20"); main_panel.add(label_server_2, "wrap 30"); main_panel.add(label_server_3, "wrap 5"); main_panel.add(choose_server, "wrap 10"); main_panel.add(label_server_4, "wrap 5"); main_panel.add(choose_language, "wrap 10"); this.setLayout(new BorderLayout()); this.add(BorderLayout.CENTER, main_panel); //Gestione eventi choose_language.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JComboBox comboBox = (JComboBox) event.getSource(); Language selected = (Language) comboBox.getSelectedItem(); selected_lang = selected; Globals.CURRENT_LOCALE = new Locale(selected.getCode()); updateLanguage(); Utility.setDefaultLangCurrent(); } }); this.setPreferredSize(this.getPreferredSize()); this.validate(); this.repaint(); }
From source file:com.game.ui.views.CharachterEditorPanel.java
@Override public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equalsIgnoreCase("dropDown")) { JComboBox comboBox = (JComboBox) ae.getSource(); JPanel panel = (JPanel) comboBox.getParent().getComponent(4); String name = comboBox.getSelectedItem().toString(); for (GameCharacter enemy : GameBean.enemyDetails) { if (enemy.getName().equalsIgnoreCase(name)) { ((JTextField) panel.getComponent(2)).setText(enemy.getName()); ((JTextField) panel.getComponent(4)).setText(enemy.getImagePath()); ((JTextField) panel.getComponent(6)).setText(new Integer(enemy.getHealth()).toString()); ((JTextField) panel.getComponent(8)).setText(new Integer(enemy.getAttackPts()).toString()); ((JTextField) panel.getComponent(10)).setText(new Integer(enemy.getArmor()).toString()); ((JTextField) panel.getComponent(12)).setText(new Integer(enemy.getAttackRange()).toString()); ((JTextField) panel.getComponent(14)).setText(new Integer(enemy.getMovement()).toString()); return; }/*from w ww . j a v a2s .c o m*/ } } else { JButton btn = (JButton) ae.getSource(); JPanel panel = (JPanel) btn.getParent(); int indexOfBtn = btn.getAccessibleContext().getAccessibleIndexInParent(); String name = ((JTextField) panel.getComponent(2)).getText(); String image = ((JTextField) panel.getComponent(4)).getText(); String health = ((JTextField) panel.getComponent(6)).getText(); String attackPts = ((JTextField) panel.getComponent(8)).getText(); String armourPts = ((JTextField) panel.getComponent(10)).getText(); String attackRnge = ((JTextField) panel.getComponent(12)).getText(); String movement = ((JTextField) panel.getComponent(14)).getText(); System.out.println("Index : " + indexOfBtn); JLabel message = ((JLabel) this.getComponent(5)); message.setText(""); message.setVisible(false); if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(image) && StringUtils.isNotBlank(health) && StringUtils.isNotBlank(attackPts) && StringUtils.isNotBlank(armourPts) && StringUtils.isNotBlank(attackRnge) && StringUtils.isNotBlank(movement)) { message.setVisible(false); GameCharacter character = new GameCharacter(); character.setName(name); character.setAttackPts(Integer.parseInt(attackPts)); character.setAttackRange(Integer.parseInt(attackRnge)); character.setHealth(Integer.parseInt(health)); character.setImagePath(image); character.setMovement(Integer.parseInt(movement)); character.setArmor(Integer.parseInt(armourPts)); boolean characterAlrdyPresent = false; for (int i = 0; i < GameBean.enemyDetails.size(); i++) { GameCharacter charFromList = GameBean.enemyDetails.get(i); if (charFromList.getName().equalsIgnoreCase(name)) { GameBean.enemyDetails.remove(i); GameBean.enemyDetails.add(i, character); characterAlrdyPresent = true; } } if (!characterAlrdyPresent) { GameBean.enemyDetails.add(character); } try { GameUtils.writeCharactersToXML(GameBean.enemyDetails, Configuration.PATH_FOR_ENEMY_CHARACTERS); message.setText("Saved Successfully.."); message.setVisible(true); if (!characterAlrdyPresent) { comboBox.addItem(name); comboBox.setSelectedItem(name); } TileInformation tileInfo = GameBean.mapInfo.getPathMap().get(location); if (tileInfo == null) { tileInfo = new TileInformation(); } tileInfo.setEnemy(character); GameBean.mapInfo.getPathMap().put(location, tileInfo); chkBox.setSelected(true); this.revalidate(); return; } catch (Exception e) { System.out.println("CharachterEditorPanel : actionPerformed() : Some error occured " + e); e.printStackTrace(); } } else { message.setText("Pls enter all the fields or pls choose a character from the drop down"); message.setVisible(true); this.revalidate(); } } }
From source file:de.fhg.iais.asc.ui.parts.TransformersPanel.java
private void appendMetadataFormatPart(StringBuilder builder, JComboBox comboBox) { Object selectedItem = comboBox.getSelectedItem(); if (selectedItem == null) { return;/*from w ww . j a va2 s .c o m*/ } String partName = selectedItem.toString(); if (!partName.equals("--")) { builder.append(partName); } }
From source file:EHRAppointment.ChartPanelDraw.java
private JComboBox createTrace() { //Create mouse trace final JComboBox trace = new JComboBox(); final String[] traceCmds = { "Enable Trace", "Disable Trace" }; trace.setModel(new DefaultComboBoxModel(traceCmds)); trace.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (traceCmds[0].equals(trace.getSelectedItem())) { chartPanel.setHorizontalAxisTrace(true); chartPanel.setVerticalAxisTrace(true); chartPanel.repaint();/*from w w w. ja va2 s.c o m*/ } else { chartPanel.setHorizontalAxisTrace(false); chartPanel.setVerticalAxisTrace(false); chartPanel.repaint(); } } }); return trace; }
From source file:components.SharedModelDemo.java
public SharedModelDemo() { super(new BorderLayout()); Vector data = new Vector(7); String[] columnNames = { "French", "Spanish", "Italian" }; String[] oneData = { "un", "uno", "uno" }; String[] twoData = { "deux", "dos", "due" }; String[] threeData = { "trois", "tres", "tre" }; String[] fourData = { "quatre", "cuatro", "quattro" }; String[] fiveData = { "cinq", "cinco", "cinque" }; String[] sixData = { "six", "seis", "sei" }; String[] sevenData = { "sept", "siete", "sette" }; //Build the model. SharedDataModel dataModel = new SharedDataModel(columnNames); dataModel.addElement(oneData);//from w w w . j a va2s . co m dataModel.addElement(twoData); dataModel.addElement(threeData); dataModel.addElement(fourData); dataModel.addElement(fiveData); dataModel.addElement(sixData); dataModel.addElement(sevenData); list = new JList(dataModel); list.setCellRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList l, Object value, int i, boolean s, boolean f) { String[] array = (String[]) value; return super.getListCellRendererComponent(l, array[0], i, s, f); } }); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); JScrollPane listPane = new JScrollPane(list); table = new JTable(dataModel); table.setSelectionModel(listSelectionModel); JScrollPane tablePane = new JScrollPane(table); //Build control area (use default FlowLayout). JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2); comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); //Build output area. output = new JTextArea(10, 40); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); //Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.X_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); listContainer.setBorder(BorderFactory.createTitledBorder("List")); listContainer.add(listPane); JPanel tableContainer = new JPanel(new GridLayout(1, 1)); tableContainer.setBorder(BorderFactory.createTitledBorder("Table")); tableContainer.add(tablePane); tablePane.setPreferredSize(new Dimension(300, 100)); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(400, 50)); topHalf.setPreferredSize(new Dimension(400, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.NORTH); bottomHalf.add(outputPane, BorderLayout.CENTER); //XXX: next line needed if bottomHalf is a scroll pane: //bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 135)); splitPane.add(bottomHalf); }
From source file:projects.tgas.exec.HrDiagram.java
/** * Main constructor.//from w w w.j a v a 2 s .c om */ public HrDiagram() { tgasStars = TgasUtils.loadTgasCatalogue(); method = METHOD.NAIVE; fMax = 1.0; final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values()); methodComboBox.setSelectedItem(method); methodComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { method = (METHOD) methodComboBox.getSelectedItem(); updateChart(); } }); final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f"); fSlider.setValue((int) Math.rint(100.0 * fMax / 2.0)); final JLabel fLabel = new JLabel(getFLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == fSlider) { // Compute fractional parallax error from slider position double newF = (2.0 * source.getValue() / 100.0); fMax = newF; fLabel.setText(getFLabel()); } updateChart(); } }; fSlider.addChangeListener(cl); // Add a bit of padding to space things out fSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Present controls below the HR diagram JPanel controls = new JPanel(new GridLayout(2, 2)); controls.add(new JLabel("Distance estimation method:")); controls.add(methodComboBox); controls.add(fLabel); controls.add(fSlider); // Initialise the ChartPanel updateChart(); // Build the panel contents setLayout(new BorderLayout()); add(hrDiagPanel, BorderLayout.CENTER); add(controls, BorderLayout.SOUTH); }
From source file:SaveImage.java
public void actionPerformed(ActionEvent e) { JComboBox cb = (JComboBox) e.getSource(); if (cb.getActionCommand().equals("SetFilter")) { setOpIndex(cb.getSelectedIndex()); repaint();//from ww w . ja v a 2 s .c om } else if (cb.getActionCommand().equals("Formats")) { /* * Save the filtered image in the selected format. The selected item will * be the name of the format to use */ String format = (String) cb.getSelectedItem(); /* * Use the format name to initialise the file suffix. Format names * typically correspond to suffixes */ File saveFile = new File("savedimage." + format); JFileChooser chooser = new JFileChooser(); chooser.setSelectedFile(saveFile); int rval = chooser.showSaveDialog(cb); if (rval == JFileChooser.APPROVE_OPTION) { saveFile = chooser.getSelectedFile(); /* * Write the filtered image in the selected format, to the file chosen * by the user. */ try { ImageIO.write(biFiltered, format, saveFile); } catch (IOException ex) { } } } }