Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "Brandon McCombs" Subject: Re: Dynamically Update JT Message-ID: X-Comment-To: comp.lang.java.gui Newsgroups: comp.lang.java.gui In-Reply-To: <1165502623.118864.282620@73g2000cwn.googlegroups.com> References: <1165502623.118864.282620@73g2000cwn.googlegroups.com> Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 84 Date: Wed, 27 Apr 2011 15:27:02 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303918022 96.60.20.240 (Wed, 27 Apr 2011 10:27:02 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:27:02 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:350 To: comp.lang.java.gui Jason Cavett wrote: > > On Dec 6, 6:33 pm, Brandon McCombs wrote: >> Jason Cavett wrote: >> >>> On Dec 6, 1:44 pm, "Jason Cavett" wrote: >>>> I'm trying to program the ability for a node on my JTree to have its >>>> icon change when the node is opened. However, althought it *seems* >>>> that the icon is benig changed (see the code below), the JTree does not >>>> refresh (or at least it doesn't appear that way). Any tips/hints/ideas >>>> on where to go with this? >>>> ((MyOwnCellRenderer) >>>> this.getCellRenderer()).setEditIcon(model.getSelected()); >>>> System.out.println(((HasrdTreeCellRenderer) >>>> this.getCellRenderer()).getIcon()); >>>> // the icon has been updated based on the println >>>> revalidate(); >>>> repaint(); >>> I think the problem has to do with how I use my cell renderer. >>> When I create my tree, I do something like this... >>> JTree tree = new JTree(); >>> tree.setCellRenderer(new MyOwnTreeCellRenderer()); >>> Within my tree cell renderer (which extends DefaultTreeCellRenderer) I >>> override the method getTreeCellRendererComponent. This is where I have >>> the logic to set icons based on what item is in the tree. The problem >>> I'm having is that if I update one icon, it updates every other node in >>> the tree. I'm not understanding how to update one single node in the >>> tree using the TreeCellRenderer (if this is even possible). >>> Any suggestions?I just used a conditional in the tree cell renderer to specify which >> icon to use so depending on the type of LDAP object I have a different icon: >> class MyTreeCellRenderer extends DefaultTreeCellRenderer >> { >> private static final long serialVersionUID = 0L; >> Font f = new Font("Arial", Font.PLAIN,11); >> public Component getTreeCellRendererComponent(JTree tree, >> Object value, boolean selected, boolean expanded, >> boolean leaf, int row, boolean hasFocus) >> { >> super.getTreeCellRendererComponent(tree, value, >> selected, expanded, leaf, row, hasFocus); >> >> Node entry = (Node)value; >> if (entry.getNodeType().equals("server")) >> setIcon(new ImageIcon(LDAPMgr.class. >> getResource("images/serverIcon.gif"))); >> else if (entry.getNodeType().equals("domain")) >> setIcon(new ImageIcon(LDAPMgr.class. >> getResource("images/domIcon.gif"))); >> else if (entry.getNodeType().equals("organizationalUnit")) >> setIcon(new ImageIcon(LDAPMgr.class. >> getResource("images/ouIcon.gif"))); >> else if (entry.getNodeType().equals("group")) >> setIcon(new ImageIcon(LDAPMgr.class. >> getResource("images/groupIcon.gif"))); >> this.setFont(f); >> return this; >> >> >> >> } >> };- Hide quoted text -- Show quoted text -- Hide quoted text -- Show quoted text - > > Well, that's what I was doing too. Problem is, the CellRenderer makes > the change to EVERY icon of that type. :-\ All I'd like it to do is > make a change to a single icon (the one that I have selected). > Well, the method that is called when a node is selected is the valueChanged() method (mine is shown below). I've never tried this but if you can manually call the getTreeCellRendererComponent() within valueChanged() then that may provide what you need. public void valueChanged(TreeSelectionEvent evt) { Node tmp = (Node)evt.getPath().getLastPathComponent(); tmp.removeAllChildren(); LDAPMgr.ldapUtility.listNodes(tmp, tmp.getDN()); model.setWorkingPath(tmp.getDN()); } --- * 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