使用eclipse“FormToolkit”,如何在swt Browser小部件上设置边框?
这是如何使用border创建Composite的方法:
Composite composite = toolkit.createComposite(parent, SWT.BORDER);
FormToolkit中没有createBrowser(),所以这是创建一个:
Browser browser = new Browser(parent, SWT.BORDER);
toolkit.adapt(browser);
问题是,即使在调用:
之后,这也不会为浏览器绘制边框toolkit.paintBordersFor(browser);
那么我该如何为浏览器创建边框?
这是一个测试应用程序:
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();
}
答案 0 :(得分:1)
拥有一致的外观&amp;感觉复合和浏览器小部件您应该将浏览器小部件包装成复合,类似于
final FormToolkit toolkit = new FormToolkit(display);
final Composite composite = toolkit.createComposite(parent, SWT.BORDER);
composite.setLayoutData(gridData);
final Composite composite2 = toolkit.createComposite(parent, SWT.BORDER);
composite2.setLayoutData(gridData);
final FillLayout layout = new FillLayout();
composite2.setLayout(layout);
final Browser browser = new Browser(composite2, SWT.NONE);
toolkit.adapt(browser);
browser.setText("<html><body>CONTENT</body></html>");
答案 1 :(得分:0)
我不太确定这是否是正确的解释,但这是我想出来的 您必须使用HTML创建边框并将其传递给浏览器 也许是因为如果你在HTML中有一个边框,你就会有一个带浏览器边框的双边框。
这是你的内容:
<html><body>CONTENT</body></html>
将其更改为:
<html><body style="border: 1px solid gray; margin: 0px; padding: 5px;">CONTENT</body></html>
测试应用程序:
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 style=\"border: 1px solid #ABADB3; margin: 0px; padding: 5px;\">CONTENT</body></html>");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
在:
后: