有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何仅当SWT视图在屏幕上滚动到时才加载它们?

我正在制作一个简单的甘特图小部件。它基本上只是一个带有自定义布局的组合。布局垂直排列所有子控件,以占据父组合的100%宽度,如下所示:

GanttLayout

下面是以这种方式排列子控件的代码:

public class GanttLayout extends Layout {

    int defaultWidth = 200;
    int width;
    int itemHeight;

    public GanttLayout(int x, int y) {
        width = x;
        itemHeight = y;

    }

    @Override
    protected Point computeSize(Composite composite, int wHint, int hHint, boolean changed) {
         int height = itemHeight * composite.getChildren().length;
         Point size = new Point(width == SWT.DEFAULT? defaultWidth: width, height + 2);
         return size;
    }

    @Override
    protected void layout(Composite composite, boolean changed) {
        int i = 0;
        for(Control control : composite.getChildren()) {
            control.setBounds(0, i * itemHeight, width == SWT.DEFAULT? composite.getSize().x: width, itemHeight);
            i++;
        }
    }

}

问题是,当添加数百个这样的子控件时,它们需要很长时间才能显示出来,然后需要很长时间才能处理所有需要处理的控件。有没有办法让这更有效?也许有一种方法可以只在用户滚动到控件时显示控件,有点像虚拟表

Here is the full code


共 (0) 个答案