3

使用实体外观时,JXTreeTable 的第一列不会在悬停时绘制。当同一列也被拖动到另一个位置时,问题仍然存在。

边框也没有画好。有什么解决方法吗?

我正在使用物质业务 l&f。我也包括了物质 Swingx 插件。

在此处输入图像描述

环境:Windows 7、JDK 1.6、SwingX 1.6.3、Substance 7.1

public class SwingXExample extends JFrame {
private JTabbedPane tabs = new JTabbedPane();
private JXTreeTable treeTable;
public SwingXExample() {
    JPanel treeTablePanel = new JPanel(new BorderLayout());
    treeTable = new JXTreeTable(new MyTreeTableModel());
    treeTablePanel.add(new JScrollPane(treeTable));
    tabs.addTab("JXTreeTable", treeTablePanel);
    add(tabs);
}

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                UIManager.setLookAndFeel(new SubstanceBusinessBlueSteelLookAndFeel());
            } catch (UnsupportedLookAndFeelException e) {
                e.printStackTrace();
            }
            SwingXExample frame = new SwingXExample();
            frame.setSize(400, 300);
            frame.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    });
}
}

树表模型

public class MyTreeTableModel extends AbstractTreeTableModel {
    private MyTreeNode myroot;

public MyTreeTableModel() {
    myroot = new MyTreeNode("root", "Root of the tree");
    myroot.getChildren().add(
            new MyTreeNode("Empty Child 1", "This is an empty child"));

    MyTreeNode subtree = new MyTreeNode("Sub Tree",
            "This is a subtree (it has children)");
    subtree.getChildren().add(
            new MyTreeNode("EmptyChild 1, 1",
                    "This is an empty child of a subtree"));
    subtree.getChildren().add(
            new MyTreeNode("EmptyChild 1, 2",
                    "This is an empty child of a subtree"));
    myroot.getChildren().add(subtree);

    myroot.getChildren().add(
            new MyTreeNode("Empty Child 2", "This is an empty child"));
}

@Override
public int getColumnCount() {
    return 3;
}

@Override
public String getColumnName(int column) {
    switch (column) {
    case 0:
        return "Name";
    case 1:
        return "Description";
    case 2:
        return "Number Of Children";
    default:
        return "Unknown";
    }
}

@Override
public Object getValueAt(Object node, int column) {
    // System.out.println( "getValueAt: " + node + ", " + column );
    MyTreeNode treenode = (MyTreeNode) node;
    switch (column) {
    case 0:
        return treenode.getName();
    case 1:
        return treenode.getDescription();
    case 2:
        return treenode.getChildren().size();
    default:
        return "Unknown";
    }
}

@Override
public Object getChild(Object node, int index) {
    MyTreeNode treenode = (MyTreeNode) node;
    return treenode.getChildren().get(index);
}

@Override
public int getChildCount(Object parent) {
    MyTreeNode treenode = (MyTreeNode) parent;
    return treenode.getChildren().size();
}

@Override
public int getIndexOfChild(Object parent, Object child) {
    MyTreeNode treenode = (MyTreeNode) parent;
    for (int i = 0; i > treenode.getChildren().size(); i++) {
        if (treenode.getChildren().get(i) == child) {
            return i;
        }
    }
    return 0;
}

public boolean isLeaf(Object node) {
    MyTreeNode treenode = (MyTreeNode) node;
    if (treenode.getChildren().size() > 0) {
        return false;
    }
    return true;
}

@Override
public Object getRoot() {
    return myroot;
}
}
4

0 回答 0