List of usage examples for javax.swing JComboBox addAncestorListener
public void addAncestorListener(AncestorListener listener)
listener
so that it will receive AncestorEvents
when it or any of its ancestors move or are made visible or invisible. From source file:idontwant2see.IDontWant2See.java
private AbstractAction getActionInputTitle(final Program p, final String part) { return new AbstractAction(mLocalizer.msg("menu.userEntered", "User entered value")) { public void actionPerformed(final ActionEvent e) { final JCheckBox caseSensitive = new JCheckBox(mLocalizer.msg("caseSensitive", "case sensitive")); String title = p.getTitle(); ArrayList<String> items = new ArrayList<String>(); if (!StringUtils.isEmpty(part)) { String shortTitle = title.trim().substring(0, title.length() - part.length()).trim(); shortTitle = StringUtils.removeEnd(shortTitle, "-").trim(); shortTitle = StringUtils.removeEnd(shortTitle, "(").trim(); items.add(shortTitle + "*"); }/*from w ww .j a v a 2 s . co m*/ int index = title.indexOf(" - "); if (index > 0) { items.add(title.substring(0, index).trim() + "*"); } items.add(title); index = title.lastIndexOf(':'); if (index > 0) { items.add(title.substring(0, index).trim() + "*"); } final JComboBox input = new JComboBox(items.toArray(new String[items.size()])); input.setEditable(true); input.addAncestorListener(new AncestorListener() { public void ancestorAdded(final AncestorEvent event) { event.getComponent().requestFocus(); } public void ancestorMoved(final AncestorEvent event) { } public void ancestorRemoved(final AncestorEvent event) { } }); if (JOptionPane.showConfirmDialog(UiUtilities.getLastModalChildOf(getParentFrame()), new Object[] { mLocalizer.msg("exclusionText", "What should be excluded? (You can use the wildcard *)"), input, caseSensitive }, mLocalizer.msg("exclusionTitle", "Exclusion value entering"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { String test = ""; String result = (String) input.getSelectedItem(); if (result != null) { test = result.replaceAll("\\*+", "\\*").trim(); if (test.length() >= 0 && !test.equals("*")) { mSettings.getSearchList() .add(new IDontWant2SeeListEntry(result, caseSensitive.isSelected())); mSettings.setLastEnteredExclusionString(result); updateFilter(!mSettings.isSwitchToMyFilter()); } } if (test.trim().length() <= 1) { JOptionPane.showMessageDialog(UiUtilities.getLastModalChildOf(getParentFrame()), mLocalizer.msg("notValid", "The entered text is not valid."), Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.ERROR_MESSAGE); } } } }; }
From source file:com.aw.swing.mvp.binding.component.BndSJTable.java
private JComboBox getJComboBox(ComboBoxModel comboBoxModel) { final JComboBox jComboBox = new JComboBox(comboBoxModel); jComboBox.addFocusListener(new CellEditableFocusListener()); jComboBox.setRequestFocusEnabled(true); jComboBox.putClientProperty(CellEditorUtils.AW_CELL_EDITOR, Boolean.TRUE); jComboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); jComboBox.addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { jComboBox.requestFocusInWindow(); }// ww w. ja v a 2 s . com public void ancestorMoved(AncestorEvent event) { } public void ancestorRemoved(AncestorEvent event) { } }); return jComboBox; }