Name: rmT116609 Date: 01/16/2002
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
DESCRIPTION OF THE PROBLEM :
JTextPane which wasn't visible shows formatted text incorrectly.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Start programm.
2. Few times click the "Click here" button.
3. Choose the "Text panel" tabbed pane.
If you select the tabbed pane "Text panel" before you click the "Click here" button, you cannot reproduce this bug.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Normally you should see the pair of lines Formatted text (bold, blue) Unformatted text (plain)
But atually you'll see that the some lines are not formatted and contain more text than has been inserted.
The problem is reproducible on Windows 2000, Solaris 2.8, Linux Redhat 6.1 using 1.3.1_02, 1.4.0-beta3.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.event.*;
public class JTextPaneTest {
private AttributeSet defSet;
private JTextPane myPane;
public JTextPaneTest() {
JFrame frm = new JFrame("Test for TextPane");
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTabbedPane tabber = new JTabbedPane();
tabber.add("Empty panel", new JPanel());
myPane = new JTextPane();
myPane.setEnabled(false);
defSet = myPane.getCharacterAttributes();
JScrollPane scroller = new JScrollPane(myPane);
scroller.setPreferredSize(new Dimension(400, 400));
tabber.add("Text panel", scroller);
frm.getContentPane().setLayout(new BorderLayout());
JButton button = new JButton("Click here");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
insertText();
}
});
frm.getContentPane().add(button, BorderLayout.NORTH);
frm.getContentPane().add(tabber, BorderLayout.CENTER);
frm.pack();
frm.show();
}
private void insertText() {
SimpleAttributeSet myAttr = new SimpleAttributeSet(defSet);
myAttr.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.TRUE);
myAttr.addAttribute(StyleConstants.ColorConstants.Foreground, Color.blue);
StyledDocument styledDocument = myPane.getStyledDocument();
try {
styledDocument.insertString(styledDocument.getLength(),
"Formatted string\n", myAttr);
styledDocument.insertString(styledDocument.getLength(),
"Unformatted string\n", defSet);
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}
public static void main(String args[]) {
new JTextPaneTest();
}
}
---------- END SOURCE ----------
(Review ID: 138351)
======================================================================