Arn*_*non 7 java swt webkit contenteditable
我想将WYSIWYG HTML编辑器添加到我的Java程序中.
我的想法是做一些像这样
,但不与蟒蛇-与Java.
我知道几个选项和他们的问题:
这是这样,我选择了与合作 浏览器对象 从org.eclipse.swt.browser包.
现在,我有下面的代码:
代码,首先创建一个浏览器对象的实例.
在此之后,它加载带有contenteditable='true'body标签属性的HTML页面.
如果它加载一个页面,它应该向contenteditable='true'body标签添加属性,当它保存页面时,它应该删除它.
我的问题是:
或者,一般情况下:
非常感谢.
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class editor {
public static void main(String [] args) {
String html = "<html><title>Editor</title>"
+ "<body contenteditable='true'>"
+ " <h2>All the Page is ditable!!!!!</h2>"
+ "<p>Heres a typical paragraph element</p>"
+ "<ol><li>and now a list</li>"
+ "<li>with only</li>"
+ "<li>three items</li>"
+ "</ol></body></html>";
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Browser browser;
try {
browser = new Browser(shell, SWT.BORDER);
}
catch (SWTError e) {
System.out.println(e.getMessage());
display.dispose();
return;
}
Composite comp = new Composite(shell, SWT.NONE);
comp.setLayout(new FillLayout(SWT.ALL));
browser.setText(html);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5116 次 |
| 最近记录: |