本文整理匯總了Java中javax.swing.JList.clearSelection方法的典型用法代碼示例。如果您正苦於以下問題:Java JList.clearSelection方法的具體用法?Java JList.clearSelection怎麽用?Java JList.clearSelection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JList
的用法示例。
在下文中一共展示了JList.clearSelection方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: reloadField
import javax.swing.JList; //導入方法依賴的package包/類
private void reloadField (JComponent component, IssueField field) {
String newValue;
newValue = task.getFieldValue(field);
boolean fieldDirty = unsavedFields.contains(field.getKey());
if (!fieldDirty) {
if (component instanceof JComboBox) {
throw new UnsupportedOperationException();
} else if (component instanceof JTextComponent) {
((JTextComponent) component).setText(newValue);
} else if (component instanceof JList) {
JList list = (JList) component;
list.clearSelection();
ListModel model = list.getModel();
for (String value : task.getFieldValues(field)) {
for (int i = 0; i < model.getSize(); i++) {
if (value.equals(model.getElementAt(i))) {
list.addSelectionInterval(i, i);
}
}
}
} else if (component instanceof JCheckBox) {
((JCheckBox) component).setSelected("1".equals(newValue));
}
}
}
示例2: matchSelection
import javax.swing.JList; //導入方法依賴的package包/類
private void matchSelection( DocumentEvent e ) {
if( isIgnoreSelectionEvents( combo ) )
return;
try {
setIgnoreSelectionEvents( combo, true );
if( !combo.isDisplayable() )
return;
String editorText;
try {
editorText = e.getDocument().getText( 0, e.getDocument().getLength() );
} catch( BadLocationException ex ) {
//ignore
return;
}
if( null != combo.getSelectedItem() && combo.getSelectedItem().toString().equals(editorText) )
return;
if( !combo.isPopupVisible() ) {
combo.showPopup();
}
JList list = getPopupList( combo );
if( null == list )
return;
int matchIndex = findMatch( combo, editorText );
if( matchIndex >= 0 ) {
list.setSelectedIndex( matchIndex );
Rectangle rect = list.getCellBounds(matchIndex, matchIndex);
if( null != rect )
list.scrollRectToVisible( rect );
} else {
list.clearSelection();
list.scrollRectToVisible( new Rectangle( 1, 1 ) );
}
} finally {
setIgnoreSelectionEvents( combo, false );
}
}
示例3: reloadField
import javax.swing.JList; //導入方法依賴的package包/類
private void reloadField (Object component, IssueField field) {
String newValue;
if (component instanceof JList) {
newValue = mergeValues(issue.getFieldValues(field));
} else {
newValue = issue.getFieldValue(field);
}
boolean fieldDirty = unsavedFields.contains(field.getKey());
if (!fieldDirty) {
if (component instanceof JComboBox) {
JComboBox combo = (JComboBox)component;
selectInCombo(combo, newValue, true);
} else if (component instanceof JTextComponent) {
((JTextComponent)component).setText(newValue);
} else if (component instanceof JList) {
JList list = (JList)component;
list.clearSelection();
ListModel model = list.getModel();
for (String value : issue.getFieldValues(field)) {
for (int i=0; i<model.getSize(); i++) {
if (value.equals(model.getElementAt(i))) {
list.addSelectionInterval(i, i);
}
}
}
} else if (component instanceof JCheckBox) {
((JCheckBox) component).setSelected("1".equals(newValue));
} else if (component instanceof IDEServices.DatePickerComponent) {
IDEServices.DatePickerComponent picker = (IDEServices.DatePickerComponent) component;
try {
picker.setDate(BugzillaIssue.DUE_DATE_FORMAT.parse(newValue));
} catch (ParseException ex) {
picker.setDate(null);
}
}
}
}