List of usage examples for javax.swing ComboBoxEditor getItem
public Object getItem();
From source file:Main.java
public void actionPerformed(ActionEvent e) { JComboBox jcb = (JComboBox) e.getSource(); System.out.println("down action"); ComboBoxUI ui = jcb.getUI();/*from w w w. ja va2 s. c o m*/ if (ui.isPopupVisible(jcb)) { int i = jcb.getSelectedIndex(); if (i < jcb.getModel().getSize() - 1) { jcb.setSelectedIndex(i + 1); jcb.repaint(); } } else { int nItems = jcb.getItemCount(); ComboBoxEditor cbe = jcb.getEditor(); String st; // Search text st = ((String) cbe.getItem()).toUpperCase(); for (int i = 0; i < nItems; i++) { String item = ((String) jcb.getItemAt(i)).toUpperCase(); if (item.startsWith(st)) { jcb.setSelectedIndex(i); break; } } ui.setPopupVisible(jcb, true); } }
From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java
/** * creates CAP for Actions Replace Text/*from www . j a va2 s. c om*/ * @param source Component */ protected void replaceText(Component source) { Component src = source; Component parent = getComponentParent() != null ? getComponentParent() : src.getParent(); if (parent instanceof JComboBox) { src = parent; } String text = null; boolean isEditable = false; boolean isCbxItem = false; boolean isSupported = true; if (src instanceof JTextComponent) { JTextComponent jtf = (JTextComponent) src; text = jtf.getText(); isEditable = jtf.isEditable(); if ((source instanceof JTextArea || source instanceof JTextPane || source instanceof JEditorPane) && (text.indexOf(CharacterConstants.LINEFEED) != -1 || text.indexOf(CharacterConstants.RETURN) != -1)) { isSupported = false; sendInfoMessage(Constants.REC_MULTILINE_MSG); } if (parent instanceof JTable) { JTable tbl = (JTable) parent; replaceTableText(src, tbl, text); return; } } if (src instanceof JComboBox) { JComboBox cbx = (JComboBox) src; isEditable = cbx.isEditable(); if (isEditable) { ComboBoxEditor cbxEditor = cbx.getEditor(); text = cbxEditor.getItem().toString(); String[] cbxItems = m_recordHelper.getRenderedComboItems(cbx); for (int i = 0; i < cbxItems.length; i++) { String item = cbxItems[i]; if (item.equals(text)) { isCbxItem = true; } } } else { return; } } if (text.length() > Constants.REC_MAX_STRING_LENGTH) { ShowObservInfoMessage infoMsg = new ShowObservInfoMessage(Constants.REC_MAX_STRING_MSG); try { AUTServer.getInstance().getServerCommunicator().send(infoMsg); } catch (CommunicationException e) { // no log available here } return; } if (m_map.get(source) != null && !(text.equals(m_map.get(source).toString())) && isSupported && isEditable && !isCbxItem) { m_map.put(src, text); IComponentIdentifier id = null; try { id = ComponentHandler.getIdentifier(src); Action a = new Action(); a = m_recordHelper.compSysToAction(id, "CompSystem.InputText"); //$NON-NLS-1$ List parameterValues = new LinkedList(); text = StringParsing.singleQuoteText(text); parameterValues.add(text); String logName = createLogicalName(src, id); createCAP(a, id, parameterValues, logName); } catch (NoIdentifierForComponentException nifce) { // no identifier for the component, log this as an error log.error("no identifier for '" + src); //$NON-NLS-1$ } } }