• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Load tree on click of button

 
Kriss Reddy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove line 5.
 
Kriss Reddy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic