Put JTable in the JTree

前端 未结 2 626
无人共我
无人共我 2020-11-27 21:59

in connection with thread Jtable as a Jtree Node I put JTable to JTree, but JTree View isn\'t rendered correctly on start_up, how can I setPreferredSize

2条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 22:25

    Get rid of the scrollPane, it's dysfunctional anyway (so far I agree with Russell :-) and add the table and its header to the panel, using an appropriate LayoutManager:

    public MyTableInTreeCellRenderer() {
        super();
        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
        table = new JTable();
        add(table.getTableHeader());
        add(table);
    }
    

    you'll probably need to tweak the visuals a bit, the left and top border lines are missing - not entirely sure which component paints them normally, could be the scrollPane

    Edit

    Forgot: the reason querying the scrollPane's prefSize in calculating the required size (done in the ui delegate, namely the VariableHeightLayoutCache) of the rendering component is that the scrollPane not yet configured with the header. The query happens before the panel is added to the rendererPane, the complete configuration is done in the table's addNotify which happens only after adding the panel to the hierarchy

提交回复
热议问题