Java 关于SWT应用程序中html页面的对话框
我在Java 关于SWT应用程序中html页面的对话框,java,eclipse,swt,eclipse-rcp,jface,Java,Eclipse,Swt,Eclipse Rcp,Jface,我在Swing中有一个about对话框,它使用JEditorPane来显示html文档(setContentType(“text/html”);)。 我想在EclipseSWT应用程序中创建一个about对话框,并显示相同的html文档,该文档将以与在Swing中相同的格式显示(超链接、br等) 我怎么能这样做?什么是合适的小部件样式文本? 我从处理程序中的浏览器开始: @Execute public void execute(final Shell currentShell){
Swing
中有一个about对话框,它使用JEditorPane
来显示html
文档(setContentType(“text/html”);
)。我想在EclipseSWT应用程序中创建一个about对话框,并显示相同的
html
文档,该文档将以与在Swing
中相同的格式显示(超链接、br等)
我怎么能这样做?什么是合适的小部件<代码>样式文本?我从
处理程序中的浏览器开始:
@Execute
public void execute(final Shell currentShell){
//load html file in textReader
Browser browser = new Browser(currentShell, SWT.NONE);
browser.setText(textReader.toString());
}
但是什么也没有显示。解决这个问题的正确方法是什么
更新:测试@Baz变更:
@Execute
public void execute(final Shell currentShell){
currentShell.setLayout(new FillLayout());
//load html file in textReader
Browser browser = new Browser(currentShell, SWT.NONE);
browser.setText(textReader.toString());
currentShell.pack();
}
它完全破坏了应用程序!加载的html覆盖了现有元素您始终可以使用良好的旧JFace对话框
和嵌入式浏览器
小部件:
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();
}
}
然后它会像这样:
很难说为什么只有这个代码示例没有显示任何内容。是否在对话框中显示浏览器?Shell
来自哪里StyledText
当前无法提供HTML。@Baz:我已将处理程序
与应用程序.e4xmi
中定义的菜单项的命令相关联。当我按下按钮时,会调用处理程序,即上面的execute
方法。我还需要为此在帖子中添加哪些代码?是的,对不起。我刚刚意识到这是一个我还不知道的日食特征。我自己无法在这里进行测试,但可以尝试在Shell
上设置FillLayout
,或者在添加浏览器后调用pack()
@Baz:检查更新!我做错了吗?您是否尝试使用其中一个建议,而不是同时使用两个建议?Composite content=new Composite(currentShell)代码>不存在compile@Cratylus再次编辑答案。下一次尝试;)这起作用了。有点不同。我扩展了TitleAreaDialog
,因为到目前为止我还没有使用Dialog
,也不想潜在地混合eclipse3和Eclipse4组件(我错了吗?。@Cratylus,正如你所看到的TitleAreaDialog
是Dialog
的一个子类。使用对话框
没有什么错。但是如果你喜欢titlearealog
,请继续使用它。使用对话框
我是否也会得到确定
-取消
?在你的屏幕截图中,我看不到它们。
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, Dialog.OK, "OK", true);
createButton(parent, Dialog.CANCEL, "Cancel", false);
}