From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3881e541598538ae X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-18 14:11:29 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!206.252.192.28!news.stealth.net!64.154.60.72.MISMATCH!cyclone2.usenetserver.com!news-out.usenetserver.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3AB5243D.DE376890@earthlink.net> From: "Marc A. Criley" Organization: Quadrus Corporation X-Mailer: Mozilla 4.73 [en] (X11; U; Linux 2.2.14-5.0 i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: JGNAT, TreeModels, and interfaces References: <3AB2080E.7C0DFB53@earthlink.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sun, 18 Mar 2001 22:08:49 GMT NNTP-Posting-Host: 158.252.122.197 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 984953329 158.252.122.197 (Sun, 18 Mar 2001 14:08:49 PST) NNTP-Posting-Date: Sun, 18 Mar 2001 14:08:49 PST Xref: supernews.google.com comp.lang.ada:5828 Date: 2001-03-18T22:08:49+00:00 List-Id: Responding to myself again, for the aid of posterity and future Deja searches :-) I went at this problem of programmatically updating a JTree a slightly different way and got everything to work. Part of the problem was that I'm still doing a lot of "programming by example" when tackling new areas, and sometimes the example can get you locked into a particular approach. Anyhow, instead of using the JTree constructor that creates a tree starting with a root node, I created a DefaultTreeModel with that root node, and then created the JTree from that DefaultTreeModel. By doing this I had access to all the DefaultTreeModel methods and it was pretty straightforward then to update the tree. Although there was a ripple effect, the fundamental change required just two lines of code. Marc "Marc A. Criley" wrote: > > With JGNAT 1.1p on RedHat Linux 6.2... > > I've built a JTree structure, and now I need to update one of its leaves > programmatically, i.e., by the program, not through user editing. > > Having generated the new leaf node, I need to inform the tree to display > it. It appears the way to do this is using the "nodeChanged" method in > the javax.swing.tree.defaultTreeModel class. > > The Ada binding to this method is: > > procedure nodeChanged > (This : access Typ; > P1_TreeNode : access javax.swing.tree.TreeNode.Typ'Class); > > where "Typ" is the DefaultTreeModel tagged type. > > So besides the new node, I also need to specify an instance of the > DefaultTreeModel. > > Here's where the problem comes in. > > To me, it seems that I ought to get the tree model from the tree using > the getModel method from javax.swing.jtree, since what I'm working with > is a Jtree. > > The method looks like this: > > function getModel > (This : access Typ) > return javax.swing.tree.TreeModel.Ref; > > I pass in my Jtree and get back a handle to a TreeModel...which is _not_ > a DefaultTreeModel. TreeModel is in fact a Java interface that > DefaultTreeModel implements. > > I can't figure out how to get that TreeModel into a form that I can pass > to a DefaultTreeModel procedure. In Java, it appears that a typecast is > performed. But this won't fly in Ada because these two classes are > independent of one another and so can't be converted. > > A DefaultTreeModel implements the TreeModel interface, so if I was > getting a DefaultTreeModel I could easily get at its TreeModel > capabilities, but I'm getting the TreeModel and somehow need to upgrade > that to a DefaultTreeModel instead. > > Suggestions are welcome :-) > > Marc A. Criley