aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Load tree on click of button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Load tree on click of button" Watch "Load tree on click of button" New topic
Author

Load tree on click of button

Kriss Reddy
Ranch Hand

Joined: Mar 29, 2005
Posts: 54
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
Posts: 18911
    
    8

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
Posts: 54
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
Posts: 18911
    
    8

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
Posts: 54
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 Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Remove line 5.


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

Joined: Mar 29, 2005
Posts: 54
Thanks Rob.
 
wood burning stoves
 
subject: Load tree on click of button