JDK-4624515 : Invisible JTextPane shows formatted text incorrectly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_2000
  • CPU: generic,x86
  • Submitted: 2002-01-16
  • Updated: 2003-06-21
  • Resolved: 2003-06-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b03Fixed
Related Reports
Duplicate :  
Relates :  
Description

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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger-b03
14-06-2004

EVALUATION Name: dsR10138 Date: 07/15/2002 When the text content isn't being painted and there is some text inserion the view tree becomes incorrect. Bug 4519711 corresponds to this problem also. This happens because the very first paragraph's layout isn't marked invalid though the corresponding element has changed. The idea of a fix is to relayout paragraph on insert/change/remove update even if the content isn't being painted. ###@###.### 2002-07-15 ======================================================================
15-07-2002