Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #711

Delete Nodes from a JTree

From "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this>
Subject Delete Nodes from a JTree
Message-ID <1169048433.158556.307590@q2g2000cwa.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:29 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
First, here is the code I've come up with so far.  I realize it's
wrong, but I wanted a place to start.

public void deleteNode() {
  TreePath[] path = this.getSelectionPaths();
  Collection<DataModel> selected = new ArrayList<DataModel>();

  for(int i=0;i<path.length;i++) {
    selected.add((DataModel) path[i].getLastPathComponent());
  }

  Iterator i = selected.iterator();

  while(i.hasNext()) {
    DataModel node = (DataModel) i.next();
    if (node.isOpen()) {
      node.notify("Close View");
    }
    node.removeFromParent();
  }

  this.setSelectionPath(null);
  this.repaint();
}

...where DataModel implement MutableTreeNode and "this" is the JTree.

Anyway, I'm getting quite a few issues when I invoke this method.  The
biggest of these is that, although the tree appears to refresh after
the delete, if I click somewhere beneath the JTree, I get an
ArrayOutOfBoundsExceptoin.  It's almost as if the nodes are still
there, but you just can't see them and they're not accessible.

I'm pretty confused about what's going on here.  Any help would be
appreciated.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | Next | Find similar | Unroll thread


Thread

Delete Nodes from a JTree "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:29 +0000

csiph-web