gpt4 book ai didi

Java SWT 文本控件在 Shell 调整大小之前不显示

转载 作者:行者123 更新时间:2023-11-30 06:35:18 24 4
gpt4 key购买 nike

我在这里的尝试基本上是在程序运行时热切换组件。如果用户按下按钮,则作为浏览器的控件将变成文本控件。我使用一个控件指向浏览器,然后将其切换为指向文本控件(在不显示的外壳上绘制在屏幕外)但是,我遇到了一些问题。当前,当按下按钮时,浏览器会消失,但在调整 shell 大小之前不会出现任何内容。

以下是相关的代码片段:

开关例程:

private void switchWindow(Control cont) {
bottomPointer.setParent(offDraw);
bottomPointer = cont;
bottomPointer.setParent(outer);
bottomPointer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
outer.redraw();
}

创建对象的buttonListener:

class textSelectionListener implements SelectionListener {
public void widgetSelected(SelectionEvent event) {
Text bottomText = new Text(offDraw, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
gd.grabExcessVerticalSpace = true;
gd.grabExcessHorizontalSpace = true;
bottomText.setLayoutData(gd);
switchWindow(bottomText);
}

还有我的调整大小监听器:

outer.addListener (SWT.Resize,  new Listener () {
//add resize listener to automatically resize both browsers
public void handleEvent (Event e) {
Rectangle clientArea = outer.getClientArea ();
browser.setLayoutData(new GridData(clientArea.width, 3*clientArea.height/5));
bottomPointer.setLayoutData(new GridData(GridData.FILL_BOTH));
}
});

我已尽一切努力解决此问题,但唯一有效的方法是调整 shell 的大小。

我可能正在处理这个可怕的错误,但这是我的第一个主要项目之一,所以我只是掌握了一些东西。

最佳答案

看来您可能需要刷新布局缓存。看到这个

Why does an SWT Composite sometimes require a call to resize() to layout correctly?

关于Java SWT 文本控件在 Shell 调整大小之前不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6221728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com