代码之家  ›  专栏  ›  技术社区  ›  jasonh

JFace应用程序窗口:CreateContents不工作

  •  1
  • jasonh  · 技术社区  · 15 年前

    我正试图创建一个分为三部分的窗口。一个不可调整大小的页眉和页脚,然后是一个内容区域,可展开以填充窗口中的其余区域。为了开始,我创建了以下类:

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

    当我这样运行它时,这会导致一个空窗口:

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

    我怎么做了,我没有看到三个标签的方式,我试图显示它们?这个 createContents 代码肯定被调用了,我可以在Eclipse的调试模式下单步执行它。

    1 回复  |  直到 15 年前
        1
  •  0
  •   jasonh    15 年前

    显然,我需要设置标签的大小和位置以使它们出现。

    推荐文章