首页 > 解决方案 > 在 SashForm 中添加到运行时的 Composite 的自动适配

问题描述

我的软件 Java 使用一个基本的插件系统,每个插件都允许您扩展一个方法,将运行时对象插入到 Composite 中,在代码中命名为“content”,并使用 BorderLayout 插入 SashForm,以允许用户管理插件的选项。

发生的情况是,在“首选项”窗口中,新元素不会自动适应大小为 0 的窗口,因此不可见。

我设法使用 setBounds () 使它们可见的唯一方法

这是插件在“首选项”窗口中创建其控件的方法的实现

class TestPref extends PreferenceNode{
        public TestPref(){
            System.out.println("Creating plugin preferences");
            setTitle("Test plugin");
        }

        @Override
        public void popolatePreferenzeComposite(Composite _composite, Properties _workbenchProp, Properties _userProp) {
            Label lblPrometeoTestPlugin = new Label(_composite, SWT.NONE);
            //lblPrometeoTestPlugin.setBounds(10, 10, 430, 15);
            lblPrometeoTestPlugin.setText("Prometeo Test Plugin v.1.0.0");

        }
    }

这是首选项窗口的一种方法,当用户单击树形菜单项时填充内容。

// Prometeo->Plugins
        String itemPrometeoPlugins=ApplicationLauncher.texts.getString("com.gega.prometeo.workbanch.preferences.tree.prometeo.plugins");
        tree.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event event) {
                if(tree.getSelection()[0].getText().equals(itemPrometeoPlugins)) {
                    clearContent();

                    Table table = new Table(content, SWT.BORDER | SWT.FULL_SELECTION);
                    table.setLayoutData(BorderLayout.CENTER);
                    table.setHeaderVisible(true);
                    table.setLinesVisible(true);

                    TableColumn tblclmnNome = new TableColumn(table, SWT.NONE);
                    tblclmnNome.setWidth(100);
                    tblclmnNome.setText("Nome");

                    TableColumn tblclmnVersione = new TableColumn(table, SWT.NONE);
                    tblclmnVersione.setWidth(100);
                    tblclmnVersione.setText("Versione");

                    TableColumn tblclmnStatus = new TableColumn(table, SWT.NONE);
                    tblclmnStatus.setWidth(100);
                    tblclmnStatus.setText("Status");

                }       
            }
        });
public void clearContent() {
        for (Control control : content.getChildren()) {
            control.dispose();
        }
    }

没有 setBounds 在此处输入图像描述 使用 setBounds 在此处输入图像描述

非常感谢大家

标签: javaswt

解决方案


我能够以这种方式使用 setBounds () 找到解决方案

table.setBounds(0,0,content.getBounds().width,content.getBounds().height)


推荐阅读