本文整理匯總了Java中javax.swing.JList.addSelectionInterval方法的典型用法代碼示例。如果您正苦於以下問題:Java JList.addSelectionInterval方法的具體用法?Java JList.addSelectionInterval怎麽用?Java JList.addSelectionInterval使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JList
的用法示例。
在下文中一共展示了JList.addSelectionInterval方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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);
}
}
}
}