Using the eclipse "FormToolkit", how do I set a border on the swt Browser widget?
This is the way how to create a Composite with border:
Composite composite = toolkit.createComposite(parent, SWT.BORDER);
There is no createBrowser() in the FormToolkit so this is how to create one:
Browser browser = new Browser(parent, SWT.BORDER);
toolkit.adapt(browser);
The problem is that this does not paint a border for the browser, even after calling:
toolkit.paintBordersFor(browser);
So how do I to create a border for the browser?
Here is a test application:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Shell");
shell.setSize(250, 250);
shell.setLayout(new FillLayout());
Composite parent = new Composite(shell, SWT.NONE);
parent.setLayout(new GridLayout(2, false));
GridData compositeGD = new GridData();
compositeGD.widthHint = 100;
compositeGD.heightHint = 100;
FormToolkit toolkit = new FormToolkit(display);
Composite composite = toolkit.createComposite(parent, SWT.BORDER);
composite.setLayoutData(compositeGD);
GridData browserGD = new GridData();
browserGD.widthHint = 100;
browserGD.heightHint = 100;
Browser browser = new Browser(parent, SWT.BORDER);
toolkit.adapt(browser);
toolkit.paintBordersFor(browser);
browser.setLayoutData(browserGD);
browser.setText("<html><body>CONTENT</body></html>");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
I'm not quite sure if this is the right explanation but this is what I came up with.
You have to create the border using HTML and pass it to the browser.
Maybe because if you have a border in the HTML you would have a double border with the Browser border.
This was your content:
Change it to something like:
The Test application:
Before: After: