aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Refreshing JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Refreshing JTree" Watch "Refreshing JTree" New topic
Author

Refreshing JTree

krish rajini
Greenhorn

Joined: Jul 02, 2008
Posts: 25
hi,

i am on creating FTP in GUI using JFC components(JTree).When server sends

the folder to client.Treeview in the client should be refreshed for

getting new folder.Please help me regarding this.

regards,

Krishnakumar.S
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
Are you familiar with JTree? If not, the Sun Java Tutorial has an extensive chapter about them. If you do know it, tell us in detail what you have so far, and where you're stuck making progress.


Ping & DNS - my free Android networking tools app
Sven Goetgeluck
Greenhorn

Joined: Jul 16, 2008
Posts: 14
Hello,

Try

SwingUtilities.UpdateComponentTree( treeinstance);

sven
krish rajini
Greenhorn

Joined: Jul 02, 2008
Posts: 25
@sven

it is working good.But after deleting the node.But when i send the new

Folder or File(means adding new node).the tree is not getting Updated.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

How do you send that new folder / file?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
krish rajini
Greenhorn

Joined: Jul 02, 2008
Posts: 25
i am not using any predefined API's.I am on creating from scratch.

When client selected the Folder to receive it in its side.A command

dout.writeUTF("FOLDER") is sent to server.

So particular Folder as a node will be updated immediately in client side

tree view.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Am I right if I think you are using your own TreeModel implementation?

If so, you need to fire an event to all TreeModelListeners. Whether that's a changed, inserted, removed or even complete structure changed event is up to you.
krish rajini
Greenhorn

Joined: Jul 02, 2008
Posts: 25
Action a3 = new AbstractAction("Refresh")
{
public void actionPerformed(ActionEvent e)
{
System.out.println("inside");
m_model.addTreeModelListener(new javax.swing.event.TreeModelListener()
{
public void treeStructureChanged(javax.swing.event.TreeModelEvent evt)
{
System.out.println(evt.getTreePath());
DefaultMutableTreeNode nn=getTreeNode(evt.getTreePath());
String sname=nn.toString();
System.out.println(sname);
m_model.reload(nn);
}
public void treeNodesRemoved(javax.swing.event.TreeModelEvent evt)
{
System.out.println(evt.getTreePath());
DefaultMutableTreeNode nn=getTreeNode(evt.getTreePath());
String sname=nn.toString();
System.out.println(sname);
m_model.reload(nn);
//System.out.println(" node changed->II"+evt.getTreePath());
}
public void treeNodesInserted(javax.swing.event.TreeModelEvent evt)
{
System.out.println(evt.getTreePath());
DefaultMutableTreeNode nn=getTreeNode(evt.getTreePath());
String sname=nn.toString();
System.out.println(sname);
m_model.reload(nn);
//System.out.println("Nodes Inserted method called..III");
}
public void treeNodesChanged(javax.swing.event.TreeModelEvent evt)
{
System.out.println(evt.getTreePath());
DefaultMutableTreeNode nn=getTreeNode(evt.getTreePath());
String sname=nn.toString();
System.out.println(sname);
m_model.reload(nn);
}
});
//SwingUtilities.updateComponentTreeUI(m_tree);
//JOptionPane.showMessageDialog(FileTree2.this,"Rename option is not implemented","Info", JOptionPane.INFORMATION_MESSAGE);
}
};
m_popup.add(a3);
m_tree.add(m_popup);
krish rajini
Greenhorn

Joined: Jul 02, 2008
Posts: 25
i used the above code to refresh the JTree.

but it is not updated.what went wrong in that code.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

When you press the tree you add a tree model listener, but that doesn't mean the tree model is actually updated. Any subsequent update should be shown though.

DefaultTreeModel has two methods called reload - one takes a TreeNode and updates that TreeNode and all of its descendants, the other one updates the entire tree.
krish rajini
Greenhorn

Joined: Jul 02, 2008
Posts: 25
i got solution for the Refreshing JTree.

Thanks and Regards,

Krishna
 
 
subject: Refreshing JTree