使用TreeColumn时树不显示

时间:2013-12-09 15:29:54

标签: java swt

我在显示包含列定义的Tree时遇到问题:

private Composite composite;
private Composite treeCompositeNdal;
private Tree treeNdalEditor;
private TreeColumn treeNameColumn ;
private TreeColumn treeValueColumn ;

[...]
treeCompositeNdal = new Composite(composite, SWT.BOTTOM);
treeCompositeNdal.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
treeCompositeNdal.setLayout(createNoMarginLayout(1, true));
treeCompositeNdal.setVisible(false);

treeNdalEditor = new Tree (treeCompositeNdal, SWT.BOTTOM|SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);

treeNdalEditor.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
treeNdalEditor.setRedraw(true);
treeNdalEditor.setVisible(true);

treeNameColumn = new TreeColumn(treeNdalEditor, 0);
treeValueColumn = new TreeColumn(treeNdalEditor, 0);
treeNameColumn.setText("Name");
treeValueColumn.setText("Value");

如果我注释掉TreetreeNameColumn行,则treeValueColumn会正常显示。我做错了什么?

1 个答案:

答案 0 :(得分:0)

填写内容后,请尝试在两列上调用TreeColumn#pack()。这将迫使TreeColumn根据其内容调整大小。