Daniel Rodrigues

Greenhorn
+ Follow
since Sep 03, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Daniel Rodrigues

Hello Gentlemen,

Just to close this thread I will add the code and some of the references I used to persist the original userObject after changes in an editable tree node.
I understood that whenever you use custom objects instead of "Strings" you will need to do that.

A very good explanation about how to work with JTree can be found in the book

"Core JFC, 2nd Edition By Kim Topley" (I could find the chapter about JTree in the web...)

"To ensure that the value stored in a node after the edit has completed is an object of the correct type, it will be necessary to supply our own tree model in which the valueForPathChanged method is overridden."

In see below my TreeModel



When treeNodesChanged is called I did:



My user object ...



This worked for me, however, I am not a Java professional and probably there are better ways to do it but I am happy with the results.
Maybe this can help someone else (I took alot of time to find out that ))))

14 years ago
Hi Thanks for your reply...

Yes, I am changing the nodes at running time (set the JTree as editable)
I found an user with exactly the same issue I have in that link "http://72.5.124.102/thread.jspa?messageID=2232016" with the subject:

Swing [Archive] - getUserObject() should really return my object, not a String object.

Look what I found.... (I believe that the previous person could explain better the issue than I)

"
When you edit a treenode, the tree sets the user object ot be a string, because it doesn't know any better...

The TreeCellRenderer (I believe) is responsible for the call to the TreeModel.valueForPathChanged(TreePath p,Object value) and it passes a String which it obtains from its editor component (a JTextField).

DefaultTreeModel then calls, MutableTreeNode.setUserObject(), hence the resulting String.

Sooo....
You have two choices:
1) rewrite TreeCellEditor to parse the String into your Thing
2) rewrite the DefaultTreeModel to convert the String to your Thing
"


Let me know if you know a easier way to fix that...

Thanks
14 years ago
Hi there...

I have JTree made of DefaultMutableTreeNode nodes. These nodes are created with a very simple user object inside.

example:

category = new DefaultMutableTreeNode(new Directory(key,hm.get(key)));

Every time I trigger the treeNodesChanged event and try to access the Directory object inside treeNodesChanged it is apparently "replaced" by a String object.

example:

public void treeNodesChanged(TreeModelEvent e) {
DefaultMutableTreeNode node;
node = (DefaultMutableTreeNode)(e.getTreePath().getLastPathComponent());
System.out.println(node.getUserObject().getClass()); -> AT THIS POINT I WAS EXPECTING TO PRINT THE DIRECTORY CLASS BUT WHAT IS RETURNED IS "class java.lang.String"
.........
....
......
..
.
}

Can someone help me understand what am I doing wrong?


Thanks in advance
14 years ago
How a event in a object can trigger an action in another object?

I created a GUI which has a Jtree inside and every time that one node in the tree is selected and right clicked a popup menu with 2 menuItems shows up.
I created the popup menu as a separate class and added an ActionListener to each menuItem. Later this popup menu was added to my Jtree. (don't know if this is a reasonable approach)
Putting some println I can see the events happening as expected but I could not figure out yet how an event inside the popup menu can initiate an action in my Jtree...like create a new node for instance.

Thanks
14 years ago
Hi Ernest

After proceeding as instructed the program worked as expected.

Thanks for your time!!!
14 years ago
I am testing different ways to read a char from System.in to learn how it works. When I use the System.in.read() function everything goes fine but when I try to use the InputStreamReader to do the same thing the program did not complain but also does not work...

public class IOkdbTest {

static Character reply;
public static void main(String[] args) throws IOException {
char mytest;
InputStreamReader isr = new InputStreamReader(System.in);
System.out.print("Enter a character: ");
reply=Character.toUpperCase((char)System.in.read()); //THIS WORKS FINE
System.out.println("Echo: "+reply);
System.out.print("Enter another character: ");
mytest = (char) isr.read(); //THIS DOES NOT WORK
System.out.println("You typed: " + mytest);
}

}

PS: I saw that in many manuals they use this method to read from keyboard... what am I missing?

Thanks in advance
14 years ago
I have a problem when i try to start a remote adminclient console.
In the server side exist a listen socket in the 900 port and is the admin server process, Don't have firewall between this machines and a telnet test to 900 port I can connect .
I use wscp locally and I can connect too but using a remote adminclient I receive this message error:
***************************************************************************
[9/2/03 14:42:35:672 BRT] 6517d320 RepositoryCli W [9/2/03 14:42:35:672
BRT] 6517d320 TraceNLS D TraceNLS instance doesn't exist for
com.ibm.ejs.resources.seriousMessages
[9/2/03 14:42:35:672 BRT] 6517d320 TraceNLS D Bundle not cached for
name com.ibm.ejs.resources.seriousMessages
[9/2/03 14:42:35:688 BRT] 6517d320 TraceNLS D Loaded ResourceBundle
com.ibm.ejs.resources.seriousMessages
ADGU1045E: Caught exception while getting initial
context:javax.naming.CommunicationException: Caught CORBA.COMM_FAILURE
when resolving initial reference=WsnNameService [Root exception is
org.omg.CORBA.COMM_FAILURE: minor code: 3 completed: No]
[9/2/03 14:42:35:688 BRT] 6517d320 RepositoryCli W ADGU1069A: Check
misspelled hostname or hostname case for admin server
[9/2/03 14:42:35:719 BRT] 6517d320 NLS > NLS, labels/en_US
[9/2/03 14:42:35:719 BRT] 6517d320 NLS < NLS
***************************************************************************
I have other WASs and their AdminServers work fine using the same adminclient.

Help me please
20 years ago