开发者

SWT Tree Item Height

开发者 https://www.devze.com 2023-01-18 12:06 出处:网络
Is it possible to have an SWT tree w开发者_开发百科ith lines of different height ? ManuelIn a SWT tree or table the items cannot different heights. If you need to make every row with different height

Is it possible to have an SWT tree w开发者_开发百科ith lines of different height ?

Manuel


In a SWT tree or table the items cannot different heights. If you need to make every row with different height, you must use a custom widget, like KTable or nebula grid for example.


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. However, this may not be what you want... having multiple font sizes in the 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.

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.


At least under Linux with GTK the following makes the first TreeItem larger than the other:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消