i want to add WYSIWYG HTML editor to my Java program.
my idea is to do Something like this
but not with python - with Java.
i know about couple of options and their problems :
That's way I chose to work with Browser Object from org.eclipse.swt.browser Package.
For now, I have the code below:
The code, first create a instance of the browser object.
After this it's load HTML page with contenteditable='true'
attributes on the body tag.
If its load a page its supposed to add contenteditable='true'
attributes to the body tag, and when its save the page it's supposed remove it.
My questions are:
Or, in general :
Thanks a lot.
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();
}
}
The DJ Native Swing project has several HTML editors, implemented using the SWT Browser (this is an implementation detail): http://djproject.sourceforge.net/ns
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With