當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。