我正在使用 SWT 创建应用程序的菜单。
在“B”类中,方法 createContents() 负责创建表单的内容:
protected void createContents() {
shell = new Shell();
shell.setSize(500, 315);
shell.setText("SWT Application");
Label lblNewLabel = new Label(shell, SWT.NONE);
lblNewLabel.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.NORMAL));
lblNewLabel.setBounds(188, 0, 108, 25);
Button btnLogs = new Button(shell, SWT.NONE);
btnLogs.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Window3 window = new Window3();
window.open();
}
});
btnLogs.setBounds(386, 242, 75, 25);
StyledText styledText = new StyledText(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
styledText.setBounds(10, 64, 357, 203);
Label lblRealTimeLogs = new Label(shell, SWT.NONE);
lblRealTimeLogs.setBounds(10, 35, 108, 15);
Button btnFilters = new Button(shell, SWT.NONE);
btnFilters.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Window2 window = new Window2();
window.open();
}
});
btnFilters.setBounds(386, 204, 75, 25);
btnFilters.setText("FILTRES");
Label lblConfiguration = new Label(shell, SWT.NONE);
lblConfiguration.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
lblConfiguration.setText("Configuraci\u00F3");
lblConfiguration.setBounds(386, 128, 88, 15);
Button btnNewButton = new Button(shell, SWT.NONE);
btnNewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Window4 window = new Window4();
window.open();
}
});
btnNewButton.setBounds(386, 165, 75, 25);
}
然后我执行应用程序并显示“B”类中的表单。问题是我需要从另一个类向 styledtext 添加新的文本行。我需要做的是,在“A”类中,它检查文件的内容,如果内容发生变化,它会将新行添加到方法 createContents() 中“B”类中创建的样式文本中...这似乎很容易,但我无法从“A”类中引用“B”类中创建的样式文本来添加这些新行......
对不起,如果不是很清楚,我的英语不是很好......
任何帮助将非常感激。谢谢。