Name: ap153225 Date: 15/09/2004
FULL PRODUCT VERSION :
java version "1.5.0"
ADDITIONAL OS VERSION INFORMATION :
Generic
A DESCRIPTION OF THE PROBLEM :
Default caret's position in JEditorPane is 0
this is unacceptable for HTML documents, cause there is invisible <head> element in zero position
and in this case caret goes invisible too.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the provided code,
and observe caret hiding
EXPECTED VERSUS ACTUAL BEHAVIOR :
The caret must be visible when JEditorPane is focused
ACTUAL -
After initialization and after setDocument() invocation for HTML documents
caret goes invisible
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JEditorPane_bugdemo {
static JEditorPane editorPane;
public static void main(String[] args) {
editorPane = new JEditorPane();
editorPane.setContentType("text/html");
editorPane.setEditable(true);
editorPane.setText("<html><body>Hello from editor pane!</body></html>");
JFrame frame = new JFrame("The mystical 0th position - part 2");
frame.getContentPane().add(editorPane);
frame.getContentPane().add(getButtonPanel(), BorderLayout.SOUTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(300, 300));
frame.setVisible(true);
editorPane.requestFocus();
}
private static JPanel getButtonPanel() {
JPanel panel = new JPanel();
JButton button = new JButton("Set text");
panel.add(button, BorderLayout.SOUTH);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editorPane.setText("Another text");
editorPane.requestFocus();
}
});
JButton button2 = new JButton("Set doc");
panel.add(button2);
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editorPane.setDocument(getTestPane().getDocument());
editorPane.requestFocus();
}
});
JButton button3 = new JButton("Alter doc");
panel.add(button3);
button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Document doc = editorPane.getDocument();
try {
doc.remove(0, doc.getLength());
} catch (BadLocationException e1) {
e1.printStackTrace();
}
editorPane.requestFocus();
}
});
return panel;
}
private static JEditorPane getTestPane() {
JEditorPane testPane = new JEditorPane();
testPane.setContentType("text/html");
testPane.setText("<html><body>Hello from test pane </body></html>");
return testPane;
}
}
---------- END SOURCE ----------
======================================================================
###@###.### 2004-09-15
###@###.### 2004-09-15