Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Display the jTree

Thread view: 
groupie - 07 Jul 2007 20:24 GMT
Hi,
I have a jTree control created via the netbeans graphical gui. It's
displaying the default 'colours', 'sports', and 'food'. The tree is
in
a jPanel which is initially invisible. After creating the tree I make
everything visible:

jTree1 = new names().buildTree();
jPanel1.setVisible(true);

names().buildTree() is returning a full jTree structure into the tree
gui (jTree1) , however when the panel is displayed, the tree is still
displaying the default. I tried jTree1.repaint() but that didn't
work.

Any ideas? Do I have to refesh the screen or something?

Thanks.
John - 07 Jul 2007 20:35 GMT
Sounds like you need to reload the tree after rebuilding it:

((DefaultTreeModel) jTree1.getModel()).reload();
groupie - 07 Jul 2007 20:54 GMT
> Sounds like you need to reload the tree after rebuilding it:
>
> ((DefaultTreeModel) jTree1.getModel()).reload();

Thanks for that, but it didn't seem to work unfortunatly. Still
display sthe default tree.
Mark Space - 08 Jul 2007 02:37 GMT
>> Sounds like you need to reload the tree after rebuilding it:
>>
>> ((DefaultTreeModel) jTree1.getModel()).reload();
>
> Thanks for that, but it didn't seem to work unfortunatly. Still
> display sthe default tree.

Where do you do the init of the JTree?  I had the same problem.
Basically, I think the correct solution is to initialize the JTree
before pack() and setVisible() is called on the higher level container
(JFrame, JWindow, etc.)

On the left, in the Inspector window, select the JTree component then
right click and open the properties window.  Select the CODE tab.  You
can add code here.  I added two lines in the pre-creation code, and one
line in the custom creation code line.  I use the minimum number of
lines because it's a pretty small box you have to enter it in, and I can
call a static method with one line, and put everything important in
there where it's easy to modify.  (As opposed to the little box in the
properties dialog, which is not easy to work with at all.)

Pre-creation:
DefaultMutableTreeNode top = new DefaultMutableTreeNode("Scenario");
createSideMenu(top);

Custom creation code:
new javax.swing.JTree(top);

Now I can just edit the "createSideMenu()" method if I need to change
anything.

I think there's a way to update the JFrame when one of it's components
is modified, but I haven't investigated it yet.  The code above goes
around the problem by making the tree correctly right from the beginning.

Good luck.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.