javax.swing.ListSelectionModel#setSelectionInterval ( )源码实例Demo

下面列出了javax.swing.ListSelectionModel#setSelectionInterval ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: SecurityRoleMappingPanel.java
/** Remove all selected items from the specified table.
 */
private void handleRemoveAction(JTable theTable) {
    int [] selectedIndices = theTable.getSelectedRows();
    if(selectedIndices.length > 0) {
        ListSelectionModel selectionModel = theTable.getSelectionModel();
        try {
            SRMBaseTableModel theModel = (SRMBaseTableModel) theTable.getModel();
            selectionModel.setValueIsAdjusting(true);
            theModel.removeElements(selectedIndices);
            int numElements = theTable.getModel().getRowCount();
            if(numElements > 0) {
                int newSelectedIndex = selectedIndices[0];
                if(newSelectedIndex >= numElements) {
                    newSelectedIndex = numElements-1;
                }
                selectionModel.setSelectionInterval(newSelectedIndex, newSelectedIndex);
            } else {
                selectionModel.clearSelection();
            }
        } finally {
            selectionModel.setValueIsAdjusting(false);
        }
    }
}
 
源代码2 项目: netbeans   文件: NotificationTable.java
void showNextSelection(boolean forward) {
    int selectedRow = this.getSelectedRow();
    int lastRowIndex = this.getRowCount() - 1;
    ListSelectionModel selection = this.getSelectionModel();
    int toSelect;
    if (forward) {
        toSelect = selectedRow + 1;
    } else {
        toSelect = selectedRow - 1;
    }
    if (toSelect < 0) {
        toSelect = lastRowIndex;
    } else if (toSelect > lastRowIndex) {
        toSelect = 0;
    }
    selection.setSelectionInterval(toSelect, toSelect);
}
 
源代码3 项目: netbeans   文件: SecurityRoleMappingPanel.java
/** Popup a dialog that lets the user add a new principal to this mapping.
 *  The new name will not be allowed to match any existing name.  The
 *  new item will be preselected afterwards.  The new name will either come
 *  from the existing master list or will be a new name and automatically added
 *  to the master list.
 */
private void handleAddPrincipalAction() {
    ListSelectionModel selectionModel = jTblPrincipals.getSelectionModel();
    try {
        selectionModel.setValueIsAdjusting(true);
        SecurityAddPrincipalPanel.addPrincipalName(this, principalTableModel, version);

        int index = principalTableModel.getRowCount()-1;
        selectionModel.setSelectionInterval(index, index);
    } finally {
        selectionModel.setValueIsAdjusting(false);
    }
}
 
源代码4 项目: netbeans   文件: SecurityRoleMappingPanel.java
/** Popup a dialog that lets the user edit the selected entry.  The changed
 *  name will not be allowed to match any existing name.  The item will
 *  remain selected once the action is completed.
 */
private void handleEditPrincipalAction() {
    int [] selectedIndices = jTblPrincipals.getSelectedRows();
    if(selectedIndices.length > 0) {
        ListSelectionModel selectionModel = jTblPrincipals.getSelectionModel();
        try {
            PrincipalNameMapping entry = principalTableModel.getElementAt(selectedIndices[0]);
            SecurityEditPrincipalPanel.editPrincipalName(this, entry, principalTableModel, version);
            selectionModel.setSelectionInterval(selectedIndices[0], selectedIndices[0]);
        } finally {
            selectionModel.setValueIsAdjusting(false);
        }
    }
}
 
源代码5 项目: netbeans   文件: SecurityRoleMappingPanel.java
/** Popup a dialog that lets the user add a new entry to the specifed master
 *  list.  The new name will not be allowed to match any existing name.  The
 *  new item will be preselected afterwards.  The new name will either come
 *  from the existing master list or will be a new name and automatically added
 *  to the master list.
 */
private void handleAddGroupAction() {
    ListSelectionModel selectionModel = jTblGroups.getSelectionModel();
    try {
        selectionModel.setValueIsAdjusting(true);
        SecurityAddGroupPanel.addGroupName(this, groupTableModel);

        int index = groupTableModel.getRowCount()-1;
        selectionModel.setSelectionInterval(index, index);
    } finally {
        selectionModel.setValueIsAdjusting(false);
    }
}
 
源代码6 项目: netbeans   文件: SecurityRoleMappingPanel.java
/** Popup a dialog that lets the user edit the selected entry.  The changed
 *  name will not be allowed to match any existing name.  The item will
 *  remain selected once the action is completed.
 */
private void handleEditGroupAction() {
    int [] selectedIndices = jTblGroups.getSelectedRows();
    if(selectedIndices.length > 0) {
        ListSelectionModel selectionModel = jTblGroups.getSelectionModel();
        try {
            String entry = groupTableModel.getElementAt(selectedIndices[0]);
            SecurityEditGroupPanel.editGroupName(this, entry, groupTableModel);
            selectionModel.setSelectionInterval(selectedIndices[0], selectedIndices[0]);
        } finally {
            selectionModel.setValueIsAdjusting(false);
        }
    }
}
 
源代码7 项目: netbeans   文件: AnnotationSettings.java
private void onUpClick() {
    ListSelectionModel listSelectionModel = getSelectionModel();
    int r = listSelectionModel.getMinSelectionIndex();        
    if(r > 0) {
        DefaultTableModel model = getModel();
        int rNew = r - 1;
        model.moveRow(r, r, rNew) ;
        listSelectionModel.setSelectionInterval(rNew, rNew);
    }
}
 
源代码8 项目: netbeans   文件: AnnotationSettings.java
private void onDownClick() {
    ListSelectionModel listSelectionModel = getSelectionModel();
    int r = listSelectionModel.getMinSelectionIndex();                
    DefaultTableModel model = getModel();
    if(r > -1 && r < model.getRowCount() - 1) {     
       int rNew = r + 1;
       model.moveRow(r, r, rNew) ;
       listSelectionModel.setSelectionInterval(rNew, rNew);
    }        
}
 
源代码9 项目: netbeans   文件: AnnotationSettings.java
private void onRemoveClick() {        
    ListSelectionModel selectionModel = getSelectionModel();
    int r = selectionModel.getMinSelectionIndex();
    if(r > -1) {
        getModel().removeRow(r);
    }
    int size = getModel().getRowCount();
    if(size > 0) {            
        if (r > size - 1) {
            r = size - 1;
        } 
        selectionModel.setSelectionInterval(r, r);    
    }
}
 
源代码10 项目: pcgen   文件: DescriptionInfoTab.java
@Override
public ModelMap createModels(CharacterFacade character)
{
	ModelMap models = new ModelMap();
	DefaultListModel<PageItem> listModel = new DefaultListModel<>();
	List<NoteInfoPane> notePaneList = new ArrayList<>();

	PageItem firstPage = new PageItem(
		character, LanguageBundle.getString("in_descBiography"), bioPane); //$NON-NLS-1$
	listModel.addElement(firstPage);
	listModel.addElement(new PageItem(
		character, LanguageBundle.getString("in_portrait"), portraitPane)); //$NON-NLS-1$
	listModel.addElement(new PageItem(
		character, LanguageBundle.getString("in_descCampHist"), histPane)); //$NON-NLS-1$

	models.put(ListModel.class, listModel);
	models.put(List.class, notePaneList);
	models.put(NoteListHandler.class, new NoteListHandler(character, listModel, notePaneList));

	ListSelectionModel model = new DefaultListSelectionModel();
	model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	model.setSelectionInterval(0, 0);
	models.put(ListSelectionModel.class, model);
	models.put(PageHandler.class, new PageHandler(model, firstPage));
	models.put(AddAction.class, new AddAction(character));

	return models;
}
 
源代码11 项目: pcgen   文件: DescriptionInfoTab.java
@Override
public ModelMap createModels(CharacterFacade character)
{
	ModelMap models = new ModelMap();
	DefaultListModel<PageItem> listModel = new DefaultListModel<>();
	List<NoteInfoPane> notePaneList = new ArrayList<>();

	PageItem firstPage = new PageItem(
		character, LanguageBundle.getString("in_descBiography"), bioPane); //$NON-NLS-1$
	listModel.addElement(firstPage);
	listModel.addElement(new PageItem(
		character, LanguageBundle.getString("in_portrait"), portraitPane)); //$NON-NLS-1$
	listModel.addElement(new PageItem(
		character, LanguageBundle.getString("in_descCampHist"), histPane)); //$NON-NLS-1$

	models.put(ListModel.class, listModel);
	models.put(List.class, notePaneList);
	models.put(NoteListHandler.class, new NoteListHandler(character, listModel, notePaneList));

	ListSelectionModel model = new DefaultListSelectionModel();
	model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	model.setSelectionInterval(0, 0);
	models.put(ListSelectionModel.class, model);
	models.put(PageHandler.class, new PageHandler(model, firstPage));
	models.put(AddAction.class, new AddAction(character));

	return models;
}
 
源代码12 项目: wandora   文件: TableSelectionModel.java
/**
* Forwards the request to the ListSelectionModel
* at the specified column.
*/
public void setLeadSelectionIndex(int row, int column) {
    ListSelectionModel lsm = getListSelectionModelAt(column);
    if (lsm.isSelectionEmpty())
        lsm.setSelectionInterval(row, row);
    else
        //calling that method throws an IndexOutOfBoundsException when selection is empty (?, JDK 1.1.8, Swing 1.1)
        lsm.setLeadSelectionIndex(row);
}
 
源代码13 项目: tcpmon   文件: Listener.java
/**
 * Method remove
 */
public void remove() {
    ListSelectionModel lsm = connectionTable.getSelectionModel();
    int bot = lsm.getMinSelectionIndex();
    int top = lsm.getMaxSelectionIndex();
    for (int i = top; i >= bot; i--) {
        ((Connection) connections.get(i - 1)).remove();
    }
    if (bot > connections.size()) {
        bot = connections.size();
    }
    lsm.setSelectionInterval(bot, bot);
}
 
源代码14 项目: tcpmon   文件: Listener.java
/**
 * Method removeAll
 */
public void removeAll() {
    ListSelectionModel lsm = connectionTable.getSelectionModel();
    lsm.clearSelection();
    while (connections.size() > 0) {
        ((Connection) connections.get(0)).remove();
    }
    lsm.setSelectionInterval(0, 0);
}
 
源代码15 项目: wandora   文件: TableSelectionModel.java
/**
* Forwards the request to the ListSelectionModel
* at the specified column.
*/
public void setSelection(int row, int column) {
    ListSelectionModel lsm = getListSelectionModelAt(column);
    lsm.setSelectionInterval(row, row);
}
 
源代码16 项目: wandora   文件: TableSelectionModel.java
/**
* Forwards the request to the ListSelectionModel
* at the specified column.
*/
public void setSelectionInterval(int row1, int row2, int column) {
    ListSelectionModel lsm = getListSelectionModelAt(column);
    lsm.setSelectionInterval(row1, row2);
}