Java ScrolledComposite子项未填充内容

Java ScrolledComposite子项未填充内容,java,swt,Java,Swt,我有一个ScrolledComposite小部件,我正在选择侦听器中初始化它(反过来连接到另一个组合)。这个ScrolledComposite依次包含另一个Composite,它依次包含一个按钮和一个标签。当内部组合出现时,它的子部件都不会出现。我以前用过很多次ScrolledComposite,我觉得一切都很好。你们谁能看出什么不对劲吗?注意,ScrolledComposite是一个类变量。还要注意的是,无论我是否在else条件下处理过该组合及其内容,这个问题都会发生 final Bu

我有一个ScrolledComposite小部件,我正在选择侦听器中初始化它(反过来连接到另一个组合)。这个ScrolledComposite依次包含另一个Composite,它依次包含一个按钮和一个标签。当内部组合出现时,它的子部件都不会出现。我以前用过很多次ScrolledComposite,我觉得一切都很好。你们谁能看出什么不对劲吗?注意,ScrolledComposite是一个类变量。还要注意的是,无论我是否在else条件下处理过该组合及其内容,这个问题都会发生

    final Button showConsole = new Button(topLeft, SWT.CHECK);
    showConsole.setText("Show Debug Console");
    showConsole.setFont(new Font(domains.getDisplay(), "Segoe UI", 9, SWT.ITALIC));
    showConsole.setSelection(false);
    showConsole.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            //The total widget group is only supposed to appear when the button is selected
            if (showConsole.getSelection()) {
                scrolledConsoleComp = new ScrolledComposite(leftComposite,
                        SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
                Composite consoleComposite = new ScrolledComposite(scrolledConsoleComp, SWT.NONE | SWT.BORDER);
                consoleComposite.setLayout(new GridLayout());
                consoleComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                consoleComposite.setVisible(true);

                scrolledConsoleComp.setContent(consoleComposite);
                scrolledConsoleComp.setExpandHorizontal(true);
                scrolledConsoleComp.setExpandVertical(true);
                scrolledConsoleComp.setLayout(new GridLayout());
                scrolledConsoleComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

                Button clear = new Button(consoleComposite, SWT.PUSH);
                clear.setText("Clear Console");

                final Label consoleText = new Label(consoleComposite, SWT.WRAP);
                consoleText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
                consoleText.setText("Messages: \n" + consoleData);
                clear.addSelectionListener(new SelectionListener() {
                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        consoleData = "";
                        consoleText.setText("Messages: \n" + consoleData);
                    }

                    @Override
                    public void widgetDefaultSelected(SelectionEvent e) {
                    }
                }); 
                scrolledConsoleComp.setMinSize(leftComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
                leftComposite.layout(true);

            } else {

                scrolledConsoleComp.setVisible(false);
                scrolledConsoleComp.dispose();
                leftComposite.layout(true);
            }
        }

我很欣赏你的见解。如果这个问题有什么不清楚的地方,请告诉我。谢谢大家!

您正在
滚动组合中创建
按钮
标签
。不会显示它们,因为未调用
setContent()

通常,
ScrolledComposite
包含一个包含所有其他小部件的
Composite

您的
consoleComposite
应该成为一个
Composite


不需要调用
setVisible()

Ah,所以所有小部件都需要调用setContent()?我想这只需要在复合材料上发生。显示了我所知道的。非常感谢。嗨,莎拉,实际上你误解了。只有ScrolledComposite才有setContent()方法。
setContent
需要在所有
ScrolledComposite
上调用-您的
consoleComposite
实际上是一个
ScrolledComposite
,这可能不是您想要的。对不起,这不是“调用”的意思。我的意思是“调用使用”。即setContent(consoluteText),setContent(清楚)等等@greg-449啊,是的,我的错。那是上次考试的延期,我忘了恢复。如果运气好的话,那就是我麻烦的根源。是的,那就是问题所在。谢谢!