简体   繁体   English

JFace ApplicationWindow:createContents无法正常工作

[英]JFace ApplicationWindow: createContents isn't working

I'm attempting to create a window that is divided into three parts. 我试图创建一个分为三个部分的窗口。 A non-resizable header and footer and then a content area that expands to fill the remaining area in the window. 不可调整大小的页眉和页脚,然后是内容区域,该区域会扩展以填充窗口中的其余区域。 To get started, I created the following class: 首先,我创建了以下课程:

public class MyWindow extends ApplicationWindow {
    Color white;
    Font mainFont;
    Font headerFont;

    public MyWindow() {
        super(null);
        }

    protected Control createContents(Composite parent) {
        Display currentDisplay = Display.getCurrent();
        white = new Color(currentDisplay, 255, 255, 255);
        mainFont = new Font(currentDisplay, "Tahoma", 8, 0);
        headerFont = new Font(currentDisplay, "Tahoma", 16, 0);

        // Main layout Composites and overall FillLayout
        Composite container = new Composite(parent, SWT.NO_RADIO_GROUP);
        Composite header = new Composite(container, SWT.NO_RADIO_GROUP);
        Composite mainContents = new Composite(container, SWT.NO_RADIO_GROUP);;
        Composite footer = new Composite(container, SWT.NO_RADIO_GROUP);;
        FillLayout containerLayout = new FillLayout(SWT.VERTICAL);
        container.setLayout(containerLayout);

        // Header
        Label headerLabel = new Label(header, SWT.LEFT);
        headerLabel.setText("Header");
        headerLabel.setFont(headerFont);

        // Main contents
        Label contentsLabel = new Label(mainContents, SWT.CENTER);
        contentsLabel.setText("Main Content Here");
        contentsLabel.setFont(mainFont);

        // Footer
        Label footerLabel = new Label(footer, SWT.CENTER);
        footerLabel.setText("Footer Here");
        footerLabel.setFont(mainFont);

        return container;
    }

    public void dispose() {
        cleanUp();
    }

    @Override
    protected void finalize() throws Throwable {
        cleanUp();
        super.finalize();
    }

    private void cleanUp() {
        if (headerFont != null) {
            headerFont.dispose();
        }
        if (mainFont != null) {
            mainFont.dispose();
        }
        if (white != null) {
            white.dispose();
        }
    }
}

And this results in an empty window when I run it like this: 当我像这样运行它时,这将导致一个空窗口:

public static void main(String[] args) {
    MyWindow myWindow = new MyWindow();
    myWindow.setBlockOnOpen(true);
    myWindow.open();
    Display.getCurrent().dispose();
}

What am I doing wrong that I don't see three labels the way I'm trying to display them? 我没有看到尝试显示三个标签的方式,这是我做错了吗? The createContents code is definitely being called, I can step through it in Eclipse in debug mode. 肯定会调用createContents代码,我可以在Eclipse的调试模式下逐步进行调试。

显然,我需要设置标签的大小和位置才能使其显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM