Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving values from property file that matches key

 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a properties file with a set of commands and their meanings
(Command = the meaning). I Populated a jtree with the keys from the properties file, now when I click a node in the jtree (key) I want the value of that selected key to go in the panel that sits in my app next to the jtree.I've tried everything to get it to work how I thought it would, I have never done this before and it's my first time posting here too!
 
Swastik Dey
Rancher
Posts: 1687
7
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the code, what you have done so far.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

*Edit - changed it, I had not closed it off after the code
Apologies but I don't know how to format the code into a small block like others have - how do you do it so I can make it look better?
 
Campbell Ritchie
Marshal
Posts: 52636
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Code tags: Don't know. I tried to correct your code tags but I don't think I did anything to them. They seem all right now, however.
I presume a lot of that code is automatically generated? I got rid of some of the excess blank lines. Never write an empty catch statement. Avoid comments like
//it will be visible
frame.setVisible(true);

because you can work that out by reading the code. Also make sure your indentation is consistent: look at lines 50/51 and 135-156.

I think that code is too much for us to be able to take it apart. I think you should start with your properties file and print it out at the command line. Then create Property objects for each Property and print them to the command line with their toString() method.

Also some dseign problems, I think.
I don't like extending Swing classes. Better not to extend JFrame, but to have a frame as a field or better still local variable. That way you can have classes which implement the display and classes which implement the underlying logic. You have actually extended JFrame, but never used the framey parts of your class. Simply let it extend Object and you have got a frame already.
Avoid myFrame.getContentPane() if you can, because it is often unnecessary.
You can read about listeners for trees in the Java Tutorials; there appear to be four sections. Unfortunately at that point I find I have forgotten everything I ever knew about trees.
 
Swastik Dey
Rancher
Posts: 1687
7
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to implement this method



and

//sets new jtree
final JTree tree = new JTree(p);
should be
tree = new JTree(p);

as you have already declared tree as instance level variable you don't need to declare it again.
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the help!I'll get those changes sorted out,yeah my code needed clearing up again,I managed to clean it up abit before posting it on here. I've only just recently gotten in to Java so I occasionally get a bit stuck and what not!
 
Campbell Ritchie
Marshal
Posts: 52636
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Alice Hampton
Ranch Hand
Posts: 217
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have any idea what i can do with this then? I'm a tad confused as to how to retrieve a value from a key value pair when the key is clicked on still and display it in my panel I know it's probably wrong I just don't know where to go with it from here anymore



Also I made the changes suggested previously and cleared up my code a bit it looks a lot better now so thanks!
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!