您可以隨時使用好老的JFace Dialog
與嵌入式Browser
部件:
public class BrowserDialog extends Dialog {
private String browserString;
protected BrowserDialog(Shell parentShell, String browserString) {
super(parentShell);
this.browserString = browserString;
}
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout(1, false);
composite.setLayout(layout);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.widthHint = 400;
data.heightHint = 400;
composite.setLayoutData(data);
Browser browser = new Browser(composite, SWT.NONE);
browser.setText(browserString);
browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
return composite;
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
}
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("About");
}
@Override
public void okPressed() {
close();
}
public static void main(String[] args)
{
final Display display = new Display();
Shell shell = new Shell(display);
Color gray = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
String hex = String.format("#%02x%02x%02x", gray.getRed(), gray.getGreen(), gray.getBlue());
new BrowserDialog(shell, "<body bgcolor='" + hex + "'><h2>TEXT</h2></body>").open();
}
}
是這樣的:
![enter image description here](https://i.stack.imgur.com/HlNlW.png)
如果你想對話框按鈕,只需將createButtonsForButtonBar(Composite parent)
方法替換爲:
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, Dialog.OK, "OK", true);
createButton(parent, Dialog.CANCEL, "Cancel", false);
}
然後,它會是這樣的:
![enter image description here](https://i.stack.imgur.com/6DCjt.png)
來源
2012-10-15 16:17:01
Baz
這很難說,爲什麼不顯示任何東西只此代碼示例。你在「對話框」中顯示瀏覽器嗎? 'Shell'從哪裏來? StyledText目前無法使用HTML。 – Baz
@Baz:我已經將一個'Handler'與一個用於在Application.e4xmi中定義的菜單項的命令關聯起來。當我按下按鈕時,處理程序即上面的'execute'方法被調用。我還需要其他哪些代碼爲此在這個帖子? – Cratylus
對,對不起。剛剛意識到這是我還不知道的Eclipse4功能。在這裏我無法測試它,但也許嘗試在'Shell'上設置'FillLayout',或者在添加Browser後調用'pack()'。 – Baz