富文本编辑器必须用Java实现,提供Swing支持,最好是开源的.
我希望将它集成到现有的Java/Swing应用程序中.
谢谢.
我正在尝试用一个小的HTML-wysiwyg,JTextPane但是我无法BackgroundAction使用它.我使用setCharacterAttributes的StyledDocument的JTextPane,但它似乎有问题.视图还可以,但事实Document并非如此.
这是一个显示问题的小型演示代码.有2个JTextPane:
JTextPane并将其设置在第二个文本上- >虽然它们具有相同的文本,但它们不会显示相同的内容.
有没有办法在当前选定的文本上设置背景颜色并让JTextPane报告更新HTML文本?
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
public class TestDifferentStyles {
private void initUI() {
JFrame frame = new JFrame(TestDifferentStyles.class.getSimpleName());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextPane textPane = new JTextPane();
final JTextPane textPane2 = new JTextPane();
textPane2.setEditable(false);
textPane.setContentType("text/html");
textPane2.setContentType("text/html");
textPane.setText("<html><head></head><body><p>Hello world</p></body></html>");
SimpleAttributeSet set = new …Run Code Online (Sandbox Code Playgroud) 我正在使用构建HTML编辑器JEditorPane,但是我遇到了一些与Foreground Actions不一致的性能问题.我的编辑器的简化版本有三个动作:将字体颜色更改为红色或蓝色,或更改字体大小.现在使用以下testFile.html文件:
<html>
<head><title>Title</title></head>
<body link="#0000FF" bgcolor="white">
<font size="4" face="arial" color="black">Some test text</font>
<font size="3" face="arial" color="black">Some new test text </font>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
有时我可以在编辑器中突出显示一些文本,然后按红色或蓝色按钮,它可以正常工作,即它会改变颜色.在其他场合(即如果我关闭我的JVM并再次启动它)颜色将不会改变直到我StyledEditorKit.FontSizeAction在相同的文本上应用.
我是如何应用的ForegroundActions?或者这可能是一些Java bug?
代码如下:
public class EditorTest extends JFrame{
private JEditorPane editorPane;
public EditorTest()
{
editorPane = new JEditorPane();
editorPane.setContentType("text/HTML");
getContentPane().add(editorPane, BorderLayout.CENTER);
editorPane.setEditorKit(new HTMLEditorKit());
Action a = new StyledEditorKit.ForegroundAction("RedColor", Color.RED);
editorPane.getActionMap().put("RedColor", a);
JToolBar bar = new JToolBar();
JButton button = new JButton("blue");
button.addActionListener(new StyledEditorKit.ForegroundAction (
"set-foreground-red", Color.blue));
bar.add(editorPane.getActionMap().get("font-size-12")).setText("12");
bar.add(button);
bar.add(editorPane.getActionMap().get("RedColor")).setText("Red");
getContentPane().add(bar, …Run Code Online (Sandbox Code Playgroud)