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

Incorrect text rendering in swing test Swing_JEditorPane/Manual/JTextPaneTest

XMLWordPrintable

    • 6
    • generic, arm
    • linux_ubuntu

      Try swing test:Swing_JEditorPane/Manual/JTextPaneTest
      text is rendered incorrectly(at least, not according to test description)
      (7b141)

      here is test source code:
      /* Bug 4242645*/

      import java.awt.*;
      import javax.swing.*;
      import javax.swing.text.*;
      import java.awt.event.*;

      public class JTextPaneTest
      {
              JTextPane jEditorPane1 = new JTextPane();
          float x = -0.5f;
              JFrame frame;

              public JTextPaneTest()
              {

                      frame = new JFrame("TextPane Rendering Test!");
                      String info = " \n\n Check while entering text in TextPane \n"+
                                    " the line spacing is consitent with Radio button \n"+
                                    " selection \n";

                                ButtonGroup group=new ButtonGroup();
                        final JRadioButton rb1=new JRadioButton("0.5");
                        final JRadioButton rb2=new JRadioButton("2");
                        rb1.setSelected(true);
                        group.add(rb1);
                        group.add(rb2);
                        JButton button1 = new JButton("Pass");
                        JButton button2 = new JButton("Fail");
                        button1.setActionCommand("Pass");
                        button2.setActionCommand("Fail");
                            ButtonListener lst = new ButtonListener();
                        button1.addActionListener(lst);
                        button2.addActionListener(lst);
                        JPanel btnpanel = new JPanel();
                        btnpanel.add(button1);
                        btnpanel.add(button2);
                                rb1.addItemListener(new ItemListener() {
                                                                public void itemStateChanged(ItemEvent event) {
                                                                        if(rb1.isSelected()){
                                                                                System.out.println("0.5 size selected");
                                                                                x=-0.5f;
                                                                               try
                                                                                              {
                                                                                                      jbInit();
                                                                                              }
                                                                                              catch(Exception e)
                                                                                              {
                                                                                                      e.printStackTrace();
                                                                                              }
                                                                                      }

                                                              }
                                });

                                 rb2.addItemListener(new ItemListener() {
                                                                public void itemStateChanged(ItemEvent event) {
                                                                        if(rb2.isSelected()){
                                                                                 System.out.println("2.0 size selected");
                                                                                x=2.0f;
                                                                                       try
                                                                                                      {
                                                                                                              jbInit();
                                                                                                      }
                                                                                                      catch(Exception e)
                                                                                                      {
                                                                                                              e.printStackTrace();
                                                                                                      }
                                                                                      }

                                                              }

                                      });

                                btnpanel.add(rb1);
                                btnpanel.add(rb2);
                        JPanel panel = new JPanel(new BorderLayout());

                    try
                                              {
                                                      jbInit();
                                              }
                                              catch(Exception e)
                                              {
                                                      e.printStackTrace();
                                              }

                              panel.add(addInfo(info),BorderLayout.NORTH);
                              panel.add(btnpanel,BorderLayout.SOUTH);
                              panel.add(jEditorPane1, BorderLayout.CENTER);
                  frame.getContentPane().add(panel);

                                frame.setSize(new Dimension(400, 300));
                                frame.setTitle("TextPane Rendering Test!");
                                frame.setSize(400,400);
                        frame.setVisible(true);
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


              }
              public static void main(String[] args)
              {
                      new JTextPaneTest();
              }
              private void jbInit() throws Exception
              {

                      System.out.println("Value of x is " +x);
                      StyleContext context = StyleContext.getDefaultStyleContext();
                      MutableAttributeSet defaultStyle = new SimpleAttributeSet();
                      StyleConstants.setFontFamily((MutableAttributeSet)defaultStyle,"Times New Roman");
                      StyleConstants.setFontSize((MutableAttributeSet)defaultStyle,12);
                      StyleConstants.setLineSpacing((MutableAttributeSet)defaultStyle,x);
                      StyleConstants.setSpaceAbove((MutableAttributeSet)defaultStyle,12f);

                      DefaultStyledDocument doc = new DefaultStyledDocument(context);
                      doc.setParagraphAttributes(0,0,defaultStyle,true);
                      jEditorPane1.setDocument(doc);

                              }

      public JScrollPane addInfo(String info) {
         JTextArea jta = new JTextArea(info,8,50);
         jta.setEditable(false);
         jta.setLineWrap(true);
         JScrollPane sp = new JScrollPane(jta);
         return sp;

      }


              class ButtonListener implements ActionListener {
             public void actionPerformed(ActionEvent ae) {
                  JButton button = (JButton)ae.getSource();
                  if(button.getActionCommand() == "Pass") {
                      System.out.println("User Evaluated Test as Passed");
                      System.exit(0);
                   } else {
                      System.out.println("User Evaluated Test as Failed");
                      System.exit(1);
                   }

            }
         } // End of ButtonListener class


      }
      List:
      Swing_JEditorPane/Manual/JTextPaneTest

            psadhukhan Prasanta Sadhukhan
            dpochepk Dmitrij Pochepko
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: