使用eclipse“FormToolkit”,如何在swt浏览器小部件上设置边框?
这是创建带边框的组合的方法:
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();
}
最佳答案
为了使复合 Material 和浏览器小部件具有一致的外观和感觉,您应该将浏览器小部件包装到复合 Material 中,例如
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>");
关于java - 使用 FormToolkit,如何在 swt 浏览器小部件上设置边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30868654/