-
Bug
-
Resolution: Unresolved
-
P3
-
None
-
6
-
x86
-
windows_2000
J2SE Version (please include all output from java -version flag):
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
Does this problem occur on J2SE 1.4.x or 5.0.x ? Yes / No (pick one)
Yes
Operating System Configuration Information (be specific):
Microsoft Windows 2000 [Version 5.00.2195]
StyledEditorKit is not updating input attributes properly
When calling setCharacterAttributes on the text at the current caret position, the input attributes are not getting updated.
1) Run Code
2) Click on the Reset Text button
3) Enter Some other text (for Example between the words Hello and World)
The Text should have been in bold, but instead is plain.
import static java.awt.BorderLayout.*;
import static javax.swing.JFrame.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
final JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(new StyledEditorKit());
editorPane.setEditable(true);
frame.add(new JButton(new AbstractAction("Reset Text") {
public void actionPerformed(ActionEvent anAction) {
try {
StyledDocument document = (StyledDocument)editorPane.getDocument();
document.remove(0, document.getLength());
document.insertString(0, "Hello World!", null);
SimpleAttributeSet attributes = new SimpleAttributeSet();
StyleConstants.setBold(attributes, true);
// Note the + 1 is to workaround bug 4280944
document.setCharacterAttributes(0, document.getLength() + 1, attributes, true);
}
catch (BadLocationException ex) {
ex.printStackTrace();
}
}
}), NORTH);
frame.add(new JScrollPane(editorPane));
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setSize(600, 600);
frame.setVisible(true);
}
}
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
Does this problem occur on J2SE 1.4.x or 5.0.x ? Yes / No (pick one)
Yes
Operating System Configuration Information (be specific):
Microsoft Windows 2000 [Version 5.00.2195]
StyledEditorKit is not updating input attributes properly
When calling setCharacterAttributes on the text at the current caret position, the input attributes are not getting updated.
1) Run Code
2) Click on the Reset Text button
3) Enter Some other text (for Example between the words Hello and World)
The Text should have been in bold, but instead is plain.
import static java.awt.BorderLayout.*;
import static javax.swing.JFrame.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
final JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKit(new StyledEditorKit());
editorPane.setEditable(true);
frame.add(new JButton(new AbstractAction("Reset Text") {
public void actionPerformed(ActionEvent anAction) {
try {
StyledDocument document = (StyledDocument)editorPane.getDocument();
document.remove(0, document.getLength());
document.insertString(0, "Hello World!", null);
SimpleAttributeSet attributes = new SimpleAttributeSet();
StyleConstants.setBold(attributes, true);
// Note the + 1 is to workaround bug 4280944
document.setCharacterAttributes(0, document.getLength() + 1, attributes, true);
}
catch (BadLocationException ex) {
ex.printStackTrace();
}
}
}), NORTH);
frame.add(new JScrollPane(editorPane));
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setSize(600, 600);
frame.setVisible(true);
}
}