Java Code Examples for javax.swing.table.DefaultTableModel#moveRow()

The following examples show how to use javax.swing.table.DefaultTableModel#moveRow() . 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: CreateTransportOrderPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private void moveDownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDownButtonActionPerformed
  int index = driveOrdersTable.getSelectedRow();

  if (index == -1) {
    return;
  }

  if (index == driveOrdersTable.getRowCount() - 1) {
    return;
  }

  DefaultTableModel model = (DefaultTableModel) driveOrdersTable.getModel();
  model.moveRow(index, index, index + 1);
  driveOrdersTable.getSelectionModel().setSelectionInterval(index + 1, index + 1);

  AbstractConnectableModelComponent location = fDestinationModels.remove(index);
  fDestinationModels.add(index + 1, location);

  String action = fActions.remove(index);
  fActions.add(index + 1, action);

  Map<String, String> properties = fPropertiesList.remove(index);
  fPropertiesList.add(index + 1, properties);

  updateButtons();
}
 
Example 2
Source File: CreateTransportOrderPanel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private void moveUpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUpButtonActionPerformed
  int index = driveOrdersTable.getSelectedRow();

  if (index <= 0) {
    return;
  }

  DefaultTableModel model = (DefaultTableModel) driveOrdersTable.getModel();
  model.moveRow(index, index, index - 1);
  driveOrdersTable.getSelectionModel().setSelectionInterval(index - 1, index - 1);

  AbstractConnectableModelComponent location = fDestinationModels.remove(index);
  fDestinationModels.add(index - 1, location);

  String action = fActions.remove(index);
  fActions.add(index - 1, action);

  Map<String, String> properties = fPropertiesList.remove(index);
  fPropertiesList.add(index - 1, properties);

  updateButtons();
}
 
Example 3
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 4
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 5
Source File: TableUtils.java    From IrScrutinizer with GNU General Public License v3.0 5 votes vote down vote up
public void tableMoveSelection(JTable table, boolean up) throws ErroneousSelectionException {
    barfIfNonconsecutiveSelection(table);
    int row = table.getSelectedRow();
    int lastRow = row + table.getSelectedRowCount() - 1;

    if (row < 0) {
        guiUtils.error("No signal selected");
        return;
    }
    DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
    if (up) {
        if (row == 0) {
            guiUtils.error("Cannot move up");
            return;
        }
    } else { // down
        if (lastRow >= tableModel.getRowCount() - 1) {
            guiUtils.error("Cannot move down");
            return;
        }
    }

    if (up) {
        tableModel.moveRow(row, lastRow, row - 1);
        table.addRowSelectionInterval(row - 1, row - 1);
        table.removeRowSelectionInterval(lastRow, lastRow);
    } else {
        tableModel.moveRow(row, lastRow, row + 1);
        table.addRowSelectionInterval(lastRow + 1, lastRow + 1);
        table.removeRowSelectionInterval(row, row);
    }
}
 
Example 6
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void drop(DropTargetDropEvent e) {
  // Transferable t = e.getTransferable();
  // DataFlavor[] f = t.getTransferDataFlavors();
  // Component c = null;
  // try {
  //   c = (Component) t.getTransferData(f[0]);
  // } catch (UnsupportedFlavorException | IOException ex) {
  //   e.dropComplete(false);
  // }
  // if (c instanceof JTable) {
  //   JTable table = (JTable) c;
  //   DefaultTableModel model = (DefaultTableModel) table.getModel();
  DefaultTableModel model = (DefaultTableModel) getModel();
  if (isDropAcceptable(e)) {
    if (targetIndex == draggedIndex) {
      setRowSelectionInterval(targetIndex, targetIndex);
    } else {
      int tg = targetIndex < draggedIndex ? targetIndex : targetIndex - 1;
      model.moveRow(draggedIndex, draggedIndex, tg);
      setRowSelectionInterval(tg, tg);
    }
    e.dropComplete(true);
  } else {
    e.dropComplete(false);
  }
  e.dropComplete(false);
  setCursor(Cursor.getDefaultCursor());
  targetIndex = -1;
  repaint();
}