• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Load tree on click of button

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 28344
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 28344
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22817
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remove line 5.
 
Kriss Reddy
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic