做了个服务器,列表中用JTREE显示在线的用户的用户名
当用户退出是如何在JTREE中删除该用户?
急啊,多谢了

解决方案 »

  1.   

    DefaultMutableTreeNode deleteNode=new DefaultMutableTreeNode(要删除的用户名);
    DefaultTreeModel treeModel;
    treeModel=(DefaultTreeModel)tree.getModel();
    treeModel.removeNodeFromParent(deleteNode);
    这样写为什么报错,该怎么改呢
    高手快帮帮我吧
      

  2.   

    这样报错是什么意思?
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at javax.swing.plaf.basic.BasicTreeUI.paintRow(Unknown Source)
    at javax.swing.plaf.basic.BasicTreeUI.paint(Unknown Source)
    at javax.swing.plaf.metal.MetalTreeUI.paint(Unknown Source)
    at javax.swing.plaf.ComponentUI.update(Unknown Source)
    at javax.swing.JComponent.paintComponent(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
    at javax.swing.RepaintManager.paint(Unknown Source)
    at javax.swing.JComponent._paintImmediately(Unknown Source)
    at javax.swing.JComponent.paintImmediately(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
      

  3.   

    deleteNode这个节点是你new出来的,因此不会带有父节点的信息.你可以尝试遍历树节点,找到和"要删除的用户名"equals的节点,再调用removeNodeFromParent这个方法