Google Tag Manager

2009/04/06

Animating JTable Rows

Code

private void testCreateActionPerformed(ActionEvent e) {
  model.addTest(new Test("New name", ""));
  (new javax.swing.Timer(DELAY, new ActionListener() {
    int i = table.convertRowIndexToView(model.getRowCount()-1);
    int h = START_HEIGHT;
    public void actionPerformed(ActionEvent e) {
      if(h < END_HEIGHT) {
        table.setRowHeight(i, h++);
      }else{
        ((javax.swing.Timer)e.getSource()).stop();
      }
    }
  })).start();
}
private void deleteActionPerformed(ActionEvent evt) {
  final int[] selection = table.getSelectedRows();
  if(selection==null || selection.length<=0) return;
  (new javax.swing.Timer(DELAY, new ActionListener() {
    int h = END_HEIGHT;
    public void actionPerformed(ActionEvent e) {
      h--;
      if(h > START_HEIGHT) {
        for(int i=selection.length-1;i >= 0;i--)
          table.setRowHeight(selection[i], h);
      }else{
        ((javax.swing.Timer)e.getSource()).stop();
        for(int i=selection.length-1;i >= 0;i--)
          model.removeRow(table.convertRowIndexToModel(selection[i]));
      }
    }
  })).start();
}

References

No comments:

Post a Comment