List of usage examples for javax.swing JComboBox getSelectedItem
public Object getSelectedItem()
From source file:eu.europa.ec.markt.tlmanager.view.pages.TreeDataPublisher.java
/** * This method handles the state of the <code>JLabel</code>'s that are associated to mandatory fields, as well as * any 'special' component. It is called via two tracks: Once by the implementation of the * <code>BindingListener</code> in <code>BindingManager</code> and once by individual action listeners for each * component. These action listeners are installed at the same time of the installation of the binding (cf. * BindingManager.setupComponent())./*w ww.j a va2s . c o m*/ * * @param component the component * @param failure if the label should express a failure */ protected void changeMandatoryComponents(Component component, boolean failure) { if (mandatoryLabels == null) { return; } for (JLabel label : mandatoryLabels) { if (label == null || component == null || label.getLabelFor() == null) { continue; } if (label.getLabelFor().equals(component)) { boolean empty = false; if (component instanceof JTextField) { JTextField tf = (JTextField) component; if (tf.getText().isEmpty()) { empty = true; } } else if (component instanceof JComboBox) { JComboBox box = (JComboBox) component; if (box.isEditable()) { final String text = ((JTextComponent) box.getEditor().getEditorComponent()).getText(); if (StringUtils.isEmpty(text) || StringUtils.equals(text, Util.DEFAULT_NO_SELECTION_ENTRY)) { empty = true; } } else { if (box.getSelectedItem().equals(Util.DEFAULT_NO_SELECTION_ENTRY)) { empty = true; } } } else if (component instanceof JXDatePicker) { JXDatePicker picker = (JXDatePicker) component; Date date = picker.getDate(); if (date == null) { empty = true; } } else if (component instanceof DateTimePicker) { DateTimePicker picker = (DateTimePicker) component; Date date = picker.getDateTime(); if (date == null) { empty = true; } } else if (component instanceof MultivalueButton) { MultivalueButton button = (MultivalueButton) component; if (button.getMultivaluePanel().getMultivalueModel().isEmpty()) { empty = true; } } else if (component instanceof CertificateProperty) { CertificateProperty certificateProperty = (CertificateProperty) component; empty = certificateProperty.isEmpty(); } if (failure || empty) { label.setForeground(Configuration.MANDATORY_COLOR); } else { label.setForeground(Configuration.NORMAL_COLOR); } break; } } }
From source file:eu.europa.ec.markt.tlmanager.view.binding.BindingManager.java
private void addListenerForEditableCombobox(final JComboBox jComboBox, final EditableComboboxListener listener) { jComboBox.addActionListener(new ActionListener() { @Override//w w w. j av a 2 s . c o m public void actionPerformed(ActionEvent arg0) { final Object selectedItem = jComboBox.getSelectedItem(); listener.itemChanged(selectedItem); } }); if (jComboBox.isEditable()) { ((JTextComponent) jComboBox.getEditor().getEditorComponent()).getDocument() .addDocumentListener(new DefaultDocumentListener() { protected void changed() { final Object item = jComboBox.getEditor().getItem(); listener.itemChanged(item); } }); } }
From source file:io.github.jeremgamer.editor.panels.Panels.java
public Panels(final JFrame frame, final PanelsPanel pp) { this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;/*from ww w .jav a 2 s .c o m*/ try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(panelList), "Nommez le panneau :", "Crer un panneau", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new PanelSave(name); PanelsPanel.updateLists(); mainPanel.addItem(name); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (panelList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/panels/" + panelList.getSelectedValue() + "/" + panelList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(panelList), "tes-vous sr de vouloir supprimer ce panneau?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { if (panelList.getSelectedValue().equals(pp.getFileName())) { pp.setFileName(""); } pp.hide(); file.delete(); File parent = new File(file.getParent()); for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { img.delete(); } parent.delete(); mainPanel.removeItem(panelList.getSelectedValue()); data.remove(panelList.getSelectedIndex()); ActionPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); mainPanel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); GeneralSave gs = new GeneralSave(); try { gs.load(new File("projects/" + Editor.getProjectName() + "/general.rbd")); gs.set("mainPanel", combo.getSelectedItem()); } catch (IOException e) { e.printStackTrace(); } } }); updateList(); panelList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); pp.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { pp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { pp.hideThenShow(); previousSelection = list.getSelectedValue(); pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); } } catch (NullPointerException npe) { pp.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); pp.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { pp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { pp.hideThenShow(); previousSelection = list.getSelectedValue(); pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); } } catch (NullPointerException npe) { pp.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(panelList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); JPanel mainPanelInput = new JPanel(); mainPanelInput.setPreferredSize(new Dimension(280, 35)); mainPanelInput.setMaximumSize(new Dimension(280, 35)); mainPanelInput.add(new JLabel("Panneau principal:")); mainPanel.setPreferredSize(new Dimension(150, 27)); mainPanelInput.add(mainPanel); this.add(mainPanelInput); }
From source file:au.org.ala.delta.editor.ui.image.ImageSettingsDialog.java
private Font fontFromComponents(JComboBox name, JComboBox sizeCombo, JCheckBox bold, JCheckBox italic) { String family = (String) name.getSelectedItem(); int size = (Integer) sizeCombo.getSelectedItem(); int style = 0; if (bold.isSelected()) { style |= Font.BOLD;/* w w w .j a v a2 s . co m*/ } if (italic.isSelected()) { style |= Font.ITALIC; } Font font = new Font(family, style, size); return font; }
From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java
/** * Helper factory method for creating a language selector that provides functionality to change the locale. * * @param width//from w w w.jav a2 s . c o m * the preferred width of the component in pixels * @return the newly created language selector */ protected JComboBox createLanguageSelector(int width) { Preconditions.checkArgument(width >= 0); final JComboBox<SupportedLocale> selector = new JComboBox(i18n.getSupportedLocales().toArray()); selector.setSelectedItem(i18n.getCurrentSupportedLocale()); selector.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { i18n.setLocale((SupportedLocale) selector.getSelectedItem()); } }); int height = selector.getPreferredSize().height; selector.setMinimumSize(new Dimension(width, height)); selector.setMaximumSize(new Dimension(width, height)); selector.setPreferredSize(new Dimension(width, height)); selector.setMaximumRowCount(i18n.getSupportedLocales().size()); selector.setComponentOrientation(ComponentOrientation.getOrientation(i18n.getLocale())); return selector; }
From source file:edu.ucla.stat.SOCR.applications.demo.BinomialTradingApplication.java
public void actionPerformed(ActionEvent evt) { /* Here we need the action listeners for all of the user-specified parameters in the COntrol-Panel * See init() method!!!/*ww w. j a v a 2 s .c o m*/ * 1.a Floating-point Text-Field for So = Price of the stock at time zero, So>=0. * 1.b Floating-Point Text-Field for EP = Exercise price (it is exercised at the end if price of stock at the end > EP), EP>=0. * 1.c Integer Slider for t = Time until expiration in years, 0<=t<=365. * 1.d Floating-Point Text-Field for r = Interest rate per year (0.000<=r). * 1.e Floating Point Text-Field for sigma = Annual volatility (0.000<=sigma). * 1.f Integer Slider for n = Number of periods that we divide the time to expiration (0<=n<=1000). */ //System.out.println(evt.getActionCommand()); if (evt.getSource() instanceof JComboBox) { JComboBox JCB = (JComboBox) evt.getSource(); choice = (String) JCB.getSelectedItem(); choice = choice.toLowerCase(); chartPanel2.validate(); inputPanel.validate(); } else if (evt.getActionCommand().equals("S0")) { So = Double.parseDouble(inSo.getText()); } else if (evt.getActionCommand().equals("EP")) { EP = Double.parseDouble(inEP.getText()); } else if (evt.getActionCommand().equals("Sigma")) { sigma = Double.parseDouble(inSigma.getText()); } else if (evt.getActionCommand().equals("Rate")) { rate = Double.parseDouble(inR.getText()); } updateAllNodes(); }
From source file:king.flow.action.DefaultMsgSendAction.java
private Map<Integer, String> retrieveConditionValues(boolean cleanCargo) { HashMap<Integer, String> contents = new HashMap<>(); for (Condition<JComponent, Component> condition : conditions) { String value = null;//from ww w .j a v a 2 s. c om int id = condition.getMeta().getId(); switch (condition.getMeta().getType()) { case TEXT_FIELD: JTextField jtf = (JTextField) condition.getComponent(); value = jtf.getText(); contents.put(id, value); break; case COMBO_BOX: JComboBox jcb = (JComboBox) condition.getComponent(); if (jcb.isEditable()) { value = jcb.getEditor().getItem().toString(); } else { value = jcb.getSelectedItem() == null ? null : jcb.getSelectedItem().toString(); } contents.put(id, value); break; case DATE: JXDatePicker jxdp = (JXDatePicker) condition.getComponent(); value = CommonUtil.toStringDate(jxdp.getDate()); contents.put(id, value); break; case PASSWORD_FIELD: boolean isEncryption = false; List<Action> action = condition.getMeta().getAction(); for (Action actionConf : action) { if (actionConf.getEncryptKeyboardAction() != null) { isEncryption = true; break; } } if (isEncryption) { getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "use encrypted keyboard mode"); value = CommonUtil.retrieveCargo(Integer.toString(id)); //check notnull condition calling this method, so cannot clean pinblock if (cleanCargo) { CommonUtil.cleanTranStation(Integer.toString(id)); } } else { getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "use normal keyboard mode"); JPasswordField jpf = (JPasswordField) condition.getComponent(); final String unwrapped = new String(jpf.getPassword()); if (unwrapped.length() > 0) { try { value = CommonUtil.inputString(unwrapped); } catch (Throwable e) { getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING, "crypto keyboard is out of work due to\n {0}", shapeErrPrompt(e)); value = unwrapped; } } else { value = unwrapped; } } contents.put(id, value); break; default: getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "Ignore useless component is : {0}", condition.getMeta().getType().value()); break; } } return contents; }
From source file:ShapeTest.java
public ShapeTestFrame() { setTitle("ShapeTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); final ShapeComponent comp = new ShapeComponent(); add(comp, BorderLayout.CENTER); final JComboBox comboBox = new JComboBox(); comboBox.addItem(new LineMaker()); comboBox.addItem(new RectangleMaker()); comboBox.addItem(new RoundRectangleMaker()); comboBox.addItem(new EllipseMaker()); comboBox.addItem(new ArcMaker()); comboBox.addItem(new PolygonMaker()); comboBox.addItem(new QuadCurveMaker()); comboBox.addItem(new CubicCurveMaker()); comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { ShapeMaker shapeMaker = (ShapeMaker) comboBox.getSelectedItem(); comp.setShapeMaker(shapeMaker); }/* ww w . j a va 2 s .c o m*/ }); add(comboBox, BorderLayout.NORTH); comp.setShapeMaker((ShapeMaker) comboBox.getItemAt(0)); }
From source file:net.lldp.checksims.ui.results.ScrollViewer.java
/** * Create a scroll viewer from a sortable Matrix Viewer * @param results the sortableMatrix to view * @param toRevalidate frame to revalidate sometimes *//*from w w w.jav a 2s . c o m*/ public ScrollViewer(SimilarityMatrix exportMatrix, SortableMatrixViewer results, JFrame toRevalidate) { resultsView = new JScrollPane(results); setBackground(Color.black); resultsView.addComponentListener(new ComponentListener() { @Override public void componentHidden(ComponentEvent arg0) { } @Override public void componentMoved(ComponentEvent arg0) { } @Override public void componentResized(ComponentEvent ce) { Dimension size = ce.getComponent().getSize(); results.padToSize(size); } @Override public void componentShown(ComponentEvent arg0) { } }); resultsView.getViewport().addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { Rectangle r = resultsView.getViewport().getViewRect(); results.setViewAt(r); } }); resultsView.setBackground(Color.black); sidebar = new JPanel(); setPreferredSize(new Dimension(900, 631)); setMinimumSize(new Dimension(900, 631)); sidebar.setPreferredSize(new Dimension(200, 631)); sidebar.setMaximumSize(new Dimension(200, 3000)); resultsView.setMinimumSize(new Dimension(700, 631)); resultsView.setPreferredSize(new Dimension(700, 631)); sidebar.setBackground(Color.GRAY); setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); this.add(sidebar); this.add(resultsView); resultsView.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); resultsView.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); resultsView.getVerticalScrollBar().setUnitIncrement(16); resultsView.getHorizontalScrollBar().setUnitIncrement(16); Integer[] presetThresholds = { 80, 60, 40, 20, 0 }; JComboBox<Integer> threshHold = new JComboBox<Integer>(presetThresholds); threshHold.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) { Integer item = (Integer) event.getItem(); results.updateThreshold(item / 100.0); toRevalidate.revalidate(); toRevalidate.repaint(); } } }); threshHold.setSelectedIndex(0); results.updateThreshold((Integer) threshHold.getSelectedItem() / 100.0); JTextField student1 = new JTextField(15); JTextField student2 = new JTextField(15); KeyListener search = new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { results.highlightMatching(student1.getText(), student2.getText()); toRevalidate.revalidate(); toRevalidate.repaint(); } @Override public void keyTyped(KeyEvent e) { } }; student1.addKeyListener(search); student2.addKeyListener(search); Collection<MatrixPrinter> printerNameSet = MatrixPrinterRegistry.getInstance() .getSupportedImplementations(); JComboBox<MatrixPrinter> exportAs = new JComboBox<>(new Vector<>(printerNameSet)); JButton exportAsSave = new JButton("Save"); JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setCurrentDirectory(new java.io.File(".")); fc.setDialogTitle("Save results"); exportAsSave.addActionListener(ae -> { MatrixPrinter method = (MatrixPrinter) exportAs.getSelectedItem(); int err = fc.showDialog(toRevalidate, "Save"); if (err == JFileChooser.APPROVE_OPTION) { try { FileUtils.writeStringToFile(fc.getSelectedFile(), method.printMatrix(exportMatrix)); } catch (InternalAlgorithmError | IOException e1) { // TODO log / show error } } }); JPanel thresholdLabel = new JPanel(); JPanel studentSearchLabel = new JPanel(); JPanel fileOutputLabel = new JPanel(); thresholdLabel.setBorder(BorderFactory.createTitledBorder("Matching Threshold")); studentSearchLabel.setBorder(BorderFactory.createTitledBorder("Student Search")); fileOutputLabel.setBorder(BorderFactory.createTitledBorder("Save Results")); thresholdLabel.add(threshHold); studentSearchLabel.add(student1); studentSearchLabel.add(student2); fileOutputLabel.add(exportAs); fileOutputLabel.add(exportAsSave); studentSearchLabel.setPreferredSize(new Dimension(200, 100)); studentSearchLabel.setMinimumSize(new Dimension(200, 100)); thresholdLabel.setPreferredSize(new Dimension(200, 100)); thresholdLabel.setMinimumSize(new Dimension(200, 100)); fileOutputLabel.setPreferredSize(new Dimension(200, 100)); fileOutputLabel.setMinimumSize(new Dimension(200, 100)); sidebar.setMaximumSize(new Dimension(200, 4000)); sidebar.add(thresholdLabel); sidebar.add(studentSearchLabel); sidebar.add(fileOutputLabel); }
From source file:com.mirth.connect.client.ui.SettingsPanelResources.java
private void typeComboBoxActionPerformed(ActionEvent evt) { JComboBox comboBox = (JComboBox) evt.getSource(); if (comboBox.isPopupVisible()) { int selectedRow = resourceTable.getSelectedRow(); if (selectedRow >= 0) { String type = (String) comboBox.getSelectedItem(); if (propertiesPanelMap.containsKey(type)) { changePropertiesPanel(type); ResourceProperties properties = currentPropertiesPanel.getDefaults(); resourceTable.getModel().setValueAt(properties, selectedRow, PROPERTIES_COLUMN); currentPropertiesPanel.setProperties(properties); getFrame().setSaveEnabled(true); }/*from www. j a v a2 s .c om*/ } } }