Java Code Examples for javax.swing.ListSelectionModel#setSelectionInterval()

The following examples show how to use javax.swing.ListSelectionModel#setSelectionInterval() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecurityRoleMappingPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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);
        }
    }
}
 
Example 2
Source File: NotificationTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: SecurityRoleMappingPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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);
    }
}
 
Example 4
Source File: SecurityRoleMappingPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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);
        }
    }
}
 
Example 5
Source File: SecurityRoleMappingPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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);
    }
}
 
Example 6
Source File: SecurityRoleMappingPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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);
        }
    }
}
 
Example 7
Source File: AnnotationSettings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 8
Source File: AnnotationSettings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
    }        
}
 
Example 9
Source File: AnnotationSettings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);    
    }
}
 
Example 10
Source File: DescriptionInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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;
}
 
Example 11
Source File: DescriptionInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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;
}
 
Example 12
Source File: TableSelectionModel.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
/**
* 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);
}
 
Example 13
Source File: Listener.java    From tcpmon with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 14
Source File: Listener.java    From tcpmon with Apache License 2.0 5 votes vote down vote up
/**
 * Method removeAll
 */
public void removeAll() {
    ListSelectionModel lsm = connectionTable.getSelectionModel();
    lsm.clearSelection();
    while (connections.size() > 0) {
        ((Connection) connections.get(0)).remove();
    }
    lsm.setSelectionInterval(0, 0);
}
 
Example 15
Source File: TableSelectionModel.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
/**
* 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);
}
 
Example 16
Source File: TableSelectionModel.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
/**
* 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);
}