This week's book giveaway is in the Android forum.
We're giving away four copies of Learning Java by Building Android Games and have Jean-Marcel Belmont on-line!
See this thread for details.
Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

JTree  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have not used JTree before. I need to show my database queries of all Student name (in alpha order) in jTree.
could anyone give me some steps to create a Jtree? I tried to read sun's tutorial..but no where they show how to connect dbquery to jtree.
thanks,
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI, I think you can set the names a -z with a FileNameFilter!But I'm not very sure!
Good luck!
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
think "TreeModel"
if you know how to get the data, get it into a TreeModel (e.g., javax.swing.tree.DefaultTreeModel or a custom model that you make yourself), then make a JTree and use setModel to put your data on the tree.
That tutorial has a section on creating a TreeModel that might be of some help.
 
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI - There really is nothing in the Core JAVA API that "Connects" a JTree and a Database. You retrieve info from the DB and then build your JTree with that information, like maggie said.
That being said, you could probably hunt the internet for some 3rd party API's that do this automagically for you. But if you are needing to learn then the best thing to do is do it yourself.
It's really not that hard once you understand the TreeModel and DefaultMutableTreeNode, etc. The JDBC stuff is a breeze.
Why don't you see what you can get, provide the code for us to see when you are having issues and we will help you through it.
BTW - It might be a good idea to get the JTree working with some static test data that is hardcoded. Once you have that working replace the hardcoded test data with data from a DB. It won't be difficult.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!