I'm using SWT to create the menu of an application.
In the class "B" the method createContents() is the responsible of create the content of the form:
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);
}
Then I execute the application and the form in the class "B" is displayed. The problem is that I need to add new lines of text to the styledtext from another class. What I need to do is that in class "A" it checks the content of a file, and if the content has changed it adds the new lines to the styledtext created in the class "B" inside the method createContents()... It seems easy but I'm not able to reference the styledtext created in the class "B" from the class "A" to add these new lines...
Sorry if it's not very clear, my english is not very good...
Any help would be much appreciated. Thanks.
Ok, I've put together a simple example that should show you how it can be done. It basically creates two classes,
A
andB
, whereA
contains aText
that is modified fromB
:Alternatively, you could make the
Text
static
an forget about the instance stuff.