SwingX JXTreeTableCellRenderer搞砸了我的桌子

时间:2015-03-23 04:14:52

标签: java swing swingx treetable

这是我的单元格渲染器类

    public class MyCellRenderer extends DefaultTreeCellRenderer{

    ImageIcon parentbill = new ImageIcon("images/parentbill.png");

    ImageIcon childbill = new ImageIcon("images/childbill.png");

    ImageIcon parentPurchase = new ImageIcon("images/parentexpense.png");

    ImageIcon childPurchase = new ImageIcon("images/childexpense.png");

    public MyCellRenderer(TreeTableController contr){
        super();
    }
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
           if(leaf){

                setIcon(childPurchase);
                //((DefaultTreeCellRenderer) c).setClosedIcon(parentPurchase);
            }else{
                setIcon(parentPurchase);    
            }

            if(expanded){
                setIcon(parentPurchase);
            }

            return c;
        }
}

我有如何添加它:

    TableModel tableModel = new TableModel(root);
    JXTreeTable treeTable = new JXTreeTable(tableModel);
    treeController = new TreeTableController(tableModel, treeTable);

    MyCellRenderer cellRenderer = new MyCellRenderer(treeController);
    treeController.getTable().setTreeCellRenderer(cellRenderer);

因此,我的渲染器应该更改表中不同行的图标。 并且,他做到了(哇!)。但他混淆桌子应该放在第一个位置,他在第一个单元格中添加了一些java垃圾,如下所示: It suppose to have word purchase in the first cell, but it appears only when i click on it 我该如何解决?我知道,有一种方法可以在没有渲染器的情况下从JXTreeTable设置图标,但是我想根据行的类型添加一些条件,所以我必须覆盖它。

0 个答案:

没有答案