JBuilder2006下如何实现自动添加jtable的各行各列的表格和jtree的各个节点呀。我用JBuilder2006在UI界面上放了一个JTREE,想请教一下各位高手如何才能不输入代码而直接靠修改jtree的某个属性或拖拽或右键添加其节点及相关事件(如弹出右键菜单或双击鼠标显示对话框的事件)呀?jtable也是类似的问题。哪位高人能帮我解决一下呀?谢谢了!

解决方案 »

  1.   

    JTable table;
    ...
    table.addMouseListener(new MouseAdapter()
        {
          public void mouseClicked(MouseEvent e)
          {
            if (e.isMetaDown())
            {
              Point p = e.getPoint();
              getContextMenu().show(table, p.x, p.y);
            }
          }
        });  public JPopupMenu getContextMenu()
      {
        JPopupMenu pop = new JPopupMenu();
        Action add = new TbAction("增加");
        Action del = new TbAction("删除");
        if (add != null)
        {
          pop.add(add);
        }
        if (del != null)
        {
          pop.add(del);
        }
        return pop.getComponentCount() > 0 ? pop : null;
      }  public class TbAction extends AbstractAction
      {
        JTable table;
        public TbAction(String name,JTable table)
        {
          super(name);
          this.table = table;
        }    public void actionPerformed(java.awt.event.ActionEvent e)
        {
          if (getValue(Action.NAME).equals("增加"))
          {
              ( (DefaultTableModel) table.getModel()).insertRow(table.getSelectedRow(), new Vector());
          }
          else if (getValue(Action.NAME).equals("删除")&&table.getSelectedRow()!=-1)
          {
              ( (DefaultTableModel) table.getModel()).removeRow(table.getSelectedRow());
          }
        }
      }
      

  2.   

    无解,怎么可能不写代码完成这些功能?建议你自己写一个父类继承JTree,把需要的功能都写到父类里面,在通过继承这个父类来实现你要的一切功能。这样也许能轻松点。
      

  3.   

    是啊,自已写一个TREE类和JTABLE类,然后再直接调用就不用写了,哈
    是不能利用JBUILDER2006添加树节点的