[英]SWT Tree Item Height
Is it possible to have an SWT tree with lines of different height ? 是否可以使用不同高度的线条的SWT树?
Manuel 曼努埃尔
In a SWT tree or table the items cannot different heights. 在SWT树或表中,项目不能具有不同的高度。 If you need to make every row with different height, you must use a custom widget, like KTable or nebula grid for example. 如果需要使每行具有不同的高度,则必须使用自定义小部件,例如KTable或星云网格 。
Well, you could of course call setFont()
on the TreeItem
in question, and give it a larger font than that used by the other TreeItem
rows. 好吧,你当然可以在有问题的TreeItem
上调用setFont()
,并给它一个比其他TreeItem
行使用的字体更大的字体。 However, this may not be what you want... having multiple font sizes in the Tree
. 但是,这可能不是您想要的...在Tree
具有多个字体大小。
A second more hack-y alternative might be to instead use the setImage()
method on TreeItem
... setting a white (or whatever) background image for each row, with the taller rows using a bigger image than the shorter rows. 另外一个hack-y替代方案可能是在TreeItem
上使用setImage()
方法...为每一行设置一个白色(或其他)背景图像,较高的行使用比较短行更大的图像。
This second approach would give you custom row heights without changing the fonts, although you would want to be sure to choose a background image of the same color as the system default background color. 第二种方法可以在不改变字体的情况下为您提供自定义行高,但您可能希望确保选择与系统默认背景颜色相同颜色的背景图像。 Perhaps you could even create your Image
objects programmatically in-memory to ensure this. 也许您甚至可以在内存中以编程方式创建Image
对象以确保这一点。
At least under Linux with GTK the following makes the first TreeItem larger than the other: 至少在使用GTK的Linux下,以下使第一个TreeItem比另一个更大:
tree.addListener(SWT.MeasureItem, new Listener() {
boolean first = true;
public void handleEvent(Event event) {
if (event.item instanceof TreeItem) {
if (first) {
event.height = event.height * 3;
first = false;
}
}
}
});
but there seems to be a minimum size for a tree item so if sou try to set is smaller it has no effect. 但似乎树项目的最小大小,所以如果尝试设置较小,它没有任何影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.