[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
Author

Load tree on click of button

Kriss Reddy
Ranch Hand

Joined: Mar 29, 2005
Messages: 50

Hi,

I am using net beans gui builder and created a JFrame with a textfiled and a button.

On click of my button I am trying to load and add a tree to the above frame as shown below.




But the tree does not load or appear on my frame. Please help.

Thanks,
Kriss.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Messages: 7177

So when the button is clicked, you create some new GUI components and fill them with data, but you don't do anything with those components. In particular you don't attach them to your JFrame in any way.

Don't do it that way. Create the components when you initialize the GUI, and just update them (via the setModel method which you know how to use) when the button is clicked.

I've never seen any tutorial which writes code that way. Which suggests to me you ought to read some tutorials before you start writing your own code. That cuts down on the guesswork immensely. Google keywords: "java swing tutorial".
Kriss Reddy
Ranch Hand

Joined: Mar 29, 2005
Messages: 50

Hello Paul,
I want to pass the file path as an argument (value of my text field) for my treee when button in clicked.

I am little confused with your reply, What are you suggesting, I should add tree to parent frame or not when button is clicked?

I am able to initialize the tree with file path when the frame is loaded, but I do not want like that. I want to load tree only when button is clicked.

Thanks,
Kriss.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Messages: 7177

Not.

When you initialize your GUI, put a JTree inside a JScrollPane in the GUI. Don't put any data into that JTree yet.

Then when the button is clicked, put data into the JTree. Don't create another JTree at that point, just put data into it.
Kriss Reddy
Ranch Hand

Joined: Mar 29, 2005
Messages: 50

Hi Paul,

Tried this, but did not work. Do I need to refresh my tree? If so how to do it, my tree mode is FileSystemModel which implements TreeModel.


Thanks,
Kriss
Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8824

Remove line 5.

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Kriss Reddy
Ranch Hand

Joined: Mar 29, 2005
Messages: 50

Thanks Rob.
 
jQuery in Action
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Swing / AWT / SWT / JFace
 
RSS feed
 
New topic
JProfiler
Get rid of your performance problems and memory leaks!