当前位置: 首页>>代码示例>>Java>>正文


Java JList.clearSelection方法代码示例

本文整理汇总了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));
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:TaskPanel.java

示例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 );
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:ComboBoxAutoCompleteSupport.java

示例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);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:IssuePanel.java


注:本文中的javax.swing.JList.clearSelection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。