在调整Shell大小之前不显示Java SWT Text控件 [英] Java SWT Text control not showing until Shell resize

查看:259
本文介绍了在调整Shell大小之前不显示Java SWT Text控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里的尝试基本上是在程序运行时热切换组件.如果用户按下按钮,则作为浏览器的控件将变成文本控件.我使用控件指向浏览器,然后将其切换为指向Text控件(该控件在非显示外壳上画在屏幕外),但是,我遇到了一些问题.当前,当按下按钮时,浏览器消失,但在调整外壳大小之前,该位置没有任何显示.

My attempt here is basically to hot-switch a component while the program is running. If the user presses a button then the control that is a browser turns into a Text control. I use a control to point to the browser and then switch it to point to the Text control(which is drawn offscreen on a non-showing shell) However, I'm having some issues. Currently when the button is pressed the browser disappears but nothing appears in it's place until the shell is resized.

以下是相关的代码段:

切换例程:

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:

The buttonListener that creates the object:

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);
    }

我的调整大小的侦听器:

And my resize listener:

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));
    }
}); 

我已经尽一切努力解决了这种情况,但是唯一起作用的是调整外壳大小.

I've tried everything to fix this situation but the only thing that has worked was to resize the shell.

我可能正在解决这个可怕的错误,但这是我最初的主要项目之一,所以我只是掌握了很多东西.

I'm probably going about this horribly wrong but this is one of my first major projects so I'm just getting the hang of things.

推荐答案

似乎您可能需要刷新布局缓存.看到这个

It seems you may need to flush the layout cache. See this

为什么SWT Composite有时需要调用resize()才能正确布局吗?

这篇关于在调整Shell大小之前不显示Java SWT Text控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆