• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Refreshing JTree

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Try

SwingUtilities.UpdateComponentTree( treeinstance);

sven
 
krish rajini
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you send that new folder / file?
 
krish rajini
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i used the above code to refresh the JTree.

but it is not updated.what went wrong in that code.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i got solution for the Refreshing JTree.

Thanks and Regards,

Krishna
 
reply
    Bookmark Topic Watch Topic
  • New Topic