Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4127002

Bug regarding setting paragraph attributes on empty paragraphs

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2.2
    • CPU:
      x86
    • OS:
      windows_nt

      Description

      ==========================================================================
      carlos.lucasius@canada 1998-04-08:
      Bug from Corel (licensee) for JFC1.1 using JDK1.1.4 on WINNT4.0.
      Corel: "Very critical bug for our product - requires immediate attention."

      There seems to be a bug with applying paragraph attributes to an empty
      paragraph. Using the accompanying test program, try the following:

          1. Type some text and press <enter>
          2. Click the 'change attributes' button. You'll notice that the
      caret changes size to match the change in paragraph style.
          3. Type more text. The paragraph attributes have changed back to
      what they were on the previous line.


      import java.awt.*;
      import java.awt.event.*;
      import com.sun.java.swing.*;
      import com.sun.java.swing.text.*;
      import com.sun.java.swing.text.html.*;

      public class bug
      {
       public static void main(String[] args)
       {
        JFrame f = new JFrame();
        JTextPane pane = new JTextPane();
        pane.setEditorKit(new HTMLEditorKit());

        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add(pane, "Center");
        JButton button = new JButton("change attributes");
        StyleChanger sc;
        button.addActionListener(sc = new StyleChanger(pane));
        sc.actionPerformed(null);
        f.getContentPane().add(button, "South");
        f.setSize(500, 600);
        f.show();
       }
      }


      class StyleChanger implements ActionListener
      {
       private JTextPane pane;
       private int counter=0;

       public StyleChanger(JTextPane p)
       {
        pane=p;
       }

       public void actionPerformed(ActionEvent e)
       {
        SimpleAttributeSet attr = new SimpleAttributeSet();

        switch(counter)
        {
         case 0:
          StyleConstants.setAlignment(attr, StyleConstants.ALIGN_LEFT);
          pane.setLogicalStyle(pane.getStyle(StyleContext.DEFAULT_STYLE));
          break;
         case 1:
          StyleConstants.setAlignment(attr, StyleConstants.ALIGN_CENTER);
          pane.setLogicalStyle(pane.getStyle("h1"));
          break;
         case 2:
          StyleConstants.setAlignment(attr, StyleConstants.ALIGN_RIGHT);
          pane.setLogicalStyle(pane.getStyle("h5"));
          break;
        }

        counter = (counter+1)%3;
        pane.setParagraphAttributes(attr, false);
        pane.requestFocus();
       }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              svioletsunw Scott Violet (Inactive)
              Reporter:
              clucasius Carlos Lucasius (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: