java - 在 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 在此处输入图像描述
非常感谢大家
解决方案
我能够以这种方式使用 setBounds () 找到解决方案
table.setBounds(0,0,content.getBounds().width,content.getBounds().height)
推荐阅读
- javascript - 刷新时加载回主页
- javascript - 克隆/复制对象时如何删除对象的只读属性?
- javascript - javascript中的警报错误。显示字符串的问题
- python - 如何使用 Jinja 将日期字符串传递到 SQL 查询中
- python - 无法使用 pip 在 Ubuntu 20.04 LTS 上安装 Tensorflow 1.x
- javascript - Throw er:如果端口和地址正确,为什么会抛出这个?
- sqlite - sqlite 和 better-sqlite3 实现之间的区别
- c# - 如何在 C# 中连接查询结果
- ruby-on-rails - Rails 4:如何从配置控制器添加动态全局变量
- python - Numba:“此错误通常是由于传递了指定函数不支持的类型的参数引起的”