ADDITIONAL SYSTEM INFORMATION :
This surely can be reproduced with Java 8 and Java 11 (with the additional modules)
A DESCRIPTION OF THE PROBLEM :
If the HTML structure contains a <br> tag not in a <p> but other paragraph-like tag eg. <h1>, the javafx.scene.web.HTMLEditor component mess up the contents simply by moving the cursor inside!
The <br> tag disappear, and the enclosing <h1> tag will be duplicated AND displayed badly, with an enormously big font size.
This can be demonstrated with this simple HTML:
<html>
<body>
<p>Move the cursor down from here</p>
<h1>
H1 before br<br>after br
</h1>
</body>
</html>
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. load this to a HTMLEditor component:
<html>
<body>
<p>Move the cursor down from here</p>
<h1>
H1 before br<br>after br
</h1>
</body>
</html>
2. Move the cursor down form the first row to the second.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The cursor moves down, nothing changed.
ACTUAL -
Visual error: The "H1 before br" line got a much more bigger font size, and a gap appears between the two H1 line.
Content error (Shown in standard output):
The original HTML structure
...
<h1>
H1 before br<br>after br
</h1>
...
changed to this:
...
<h1><h1>
H1 before br</h1>after br
</h1>
...
This behaviur is unacceptable.
---------- BEGIN SOURCE ----------
package test;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.HTMLEditor;
public class TestHTMLEditorH1Br extends JFXPanel {
private HTMLEditor editor;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
// # Start test
JFrame testForm = initTestForm(new TestHTMLEditorH1Br());
testForm.show();
}
});
}
public static JFrame initTestForm(JComponent content) {
JFrame frame = new JFrame();
frame.setTitle("HTMLEditor");
frame.setPreferredSize(new Dimension(800, 600));
frame.getContentPane().add(content);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
return frame;
}
public TestHTMLEditorH1Br() {
Platform.runLater(this::makeEditor);
}
public void makeEditor() {
try {
editor = new HTMLEditor();
editor.lookup("WebView").setOnKeyReleased(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
printEditor();
}
});
Scene scene = new Scene(new BorderPane(editor));
setScene(scene);
/*
<html>
<body>
<p>Move the cursor down from here</p>
<h1>
H1 before br<br>after br
</h1>
</body>
</html>
*/
String content = "<html>\r\n" +
"<body>\r\n" +
"<p>Move the cursor down from here</p>\r\n" +
"<h1>\r\n" +
"H1 before br<br>after br\r\n" +
"</h1>\r\n" +
"</body>\r\n" +
"</html>";
editor.setHtmlText(content);
printEditor();
} catch (Exception e) {
e.printStackTrace();
}
}
public void printEditor() {
System.out.println("------------------");
System.out.println(editor.getHtmlText());
System.out.println("------------------");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
No workaround found yet.
FREQUENCY : always
This surely can be reproduced with Java 8 and Java 11 (with the additional modules)
A DESCRIPTION OF THE PROBLEM :
If the HTML structure contains a <br> tag not in a <p> but other paragraph-like tag eg. <h1>, the javafx.scene.web.HTMLEditor component mess up the contents simply by moving the cursor inside!
The <br> tag disappear, and the enclosing <h1> tag will be duplicated AND displayed badly, with an enormously big font size.
This can be demonstrated with this simple HTML:
<html>
<body>
<p>Move the cursor down from here</p>
<h1>
H1 before br<br>after br
</h1>
</body>
</html>
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. load this to a HTMLEditor component:
<html>
<body>
<p>Move the cursor down from here</p>
<h1>
H1 before br<br>after br
</h1>
</body>
</html>
2. Move the cursor down form the first row to the second.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The cursor moves down, nothing changed.
ACTUAL -
Visual error: The "H1 before br" line got a much more bigger font size, and a gap appears between the two H1 line.
Content error (Shown in standard output):
The original HTML structure
...
<h1>
H1 before br<br>after br
</h1>
...
changed to this:
...
<h1><h1>
H1 before br</h1>after br
</h1>
...
This behaviur is unacceptable.
---------- BEGIN SOURCE ----------
package test;
import java.awt.Dimension;
import java.awt.EventQueue;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.HTMLEditor;
public class TestHTMLEditorH1Br extends JFXPanel {
private HTMLEditor editor;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
// # Start test
JFrame testForm = initTestForm(new TestHTMLEditorH1Br());
testForm.show();
}
});
}
public static JFrame initTestForm(JComponent content) {
JFrame frame = new JFrame();
frame.setTitle("HTMLEditor");
frame.setPreferredSize(new Dimension(800, 600));
frame.getContentPane().add(content);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
return frame;
}
public TestHTMLEditorH1Br() {
Platform.runLater(this::makeEditor);
}
public void makeEditor() {
try {
editor = new HTMLEditor();
editor.lookup("WebView").setOnKeyReleased(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
printEditor();
}
});
Scene scene = new Scene(new BorderPane(editor));
setScene(scene);
/*
<html>
<body>
<p>Move the cursor down from here</p>
<h1>
H1 before br<br>after br
</h1>
</body>
</html>
*/
String content = "<html>\r\n" +
"<body>\r\n" +
"<p>Move the cursor down from here</p>\r\n" +
"<h1>\r\n" +
"H1 before br<br>after br\r\n" +
"</h1>\r\n" +
"</body>\r\n" +
"</html>";
editor.setHtmlText(content);
printEditor();
} catch (Exception e) {
e.printStackTrace();
}
}
public void printEditor() {
System.out.println("------------------");
System.out.println(editor.getHtmlText());
System.out.println("------------------");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
No workaround found yet.
FREQUENCY : always