使用Java和Webkit的HTML编辑器 – SWT浏览器
|
我想将WYSIWYG
HTML编辑器添加到我的
Java程序中.
我的想法是做像 this这样的事情 但不是用python – 用Java. 我知道几个选项及其问题: > HTMLEditorKit – 不够复杂. 这是我选择合作的方式 现在,我有以下代码: 我的问题是: >如何获取已编辑的HTML代码? 或者,一般来说: > >有可能吗? 非常感谢. 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();
}
}
解决方法
DJ Native Swing项目有几个HTML编辑器,使用SWT浏览器实现(这是一个实现细节):
http://djproject.sourceforge.net/ns
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
