本文整理汇总了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);
}
}
}
}