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

Can't print LTR text displayed in JTextPane (explicit RTL)

XMLWordPrintable



      Name: jbT81659 Date: 08/30/2000

      OS: Win98
      JDK: jdk1.3.-FCS_C

      LTR text displayed in JTextPane (explicit RTL) is not printed.

      To reproduce bug:

      1- Compile and run the following code
      2- To print application, press "Print entire Frame" button
      3- Compare printed frame with displayed frame
      4- Note that LTR text displayed in JTextPane is not printed on paper

      -------Code-----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.GridLayout;
      import java.util.*;
      import java.awt.font.*;
      import javax.swing.text.*;

      public class JTP3_explicit_RTL_right extends JFrame implements ActionListener
      {
         JLabel l, label, label2;
         JLabel whatisIt;
         JButton printFrame, printInside;
         JPanel panel;
         JTextField field;
         JPanel p;
         JTextArea area;
         JTextPane pane;

         public JTP3_explicit_RTL_right()
         {
             super("JTP3_explicit_RTL_right");

          printFrame = new JButton("Print entire frame ");
          printInside = new JButton("print components inside frame");
          printFrame.addActionListener(this);
          printInside.addActionListener(this);
             
          panel = new JPanel(new FlowLayout(FlowLayout.LEFT));

          p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
          l = new JLabel("JTP3 explicit RTL, right");
          l.setVerticalAlignment(SwingConstants.BOTTOM);
          l.setFont(new Font("Lucida Sans Regular",Font.PLAIN,10));
          pane = new JTextPane();
          pane.getDocument().putProperty(TextAttribute.RUN_DIRECTION,TextAttribute.RUN_DIRECTION_RTL);
          pane.setFont(new Font("Lucida Sans Regular",Font.PLAIN,10));
          MutableAttributeSet rightStyle;
          rightStyle = new SimpleAttributeSet();
          StyleConstants.setAlignment(rightStyle,StyleConstants.ALIGN_RIGHT);
          StyledDocument doc = pane.getStyledDocument();
          SimpleAttributeSet a = new SimpleAttributeSet();
          pane.setParagraphAttributes(rightStyle,true);
          pane.setPreferredSize(new Dimension(180,250));
          pane.setText("This is a test ");
          p.add(l);
          p.add(pane);
          p.setPreferredSize(new Dimension(175,160));
          panel.add(p);
          whatisIt = new JLabel("This example prints JTextPane, explicit RTL, right");
          panel.add(printFrame);
          panel.add(printInside);
          panel.add(whatisIt);
          panel.setPreferredSize(new Dimension(200,1900));
          JScrollPane scroll = new JScrollPane(panel);
          scroll.setPreferredSize(new Dimension(300,250));

          getContentPane().add(scroll);

         }
         public void actionPerformed(ActionEvent e)
         {
             printFrame.setEnabled(false);
             printInside.setEnabled(false);
             Properties prnProp = new Properties();
             PrintJob prnJob = Toolkit.getDefaultToolkit().getPrintJob(JTP3_explicit_RTL_right.this, "TEST", prnProp);
             if (prnJob != null)
             {
                JButton b = (JButton)e.getSource();
                Component c;
                Graphics prnGr = prnJob.getGraphics();
                c = JTP3_explicit_RTL_right.this;
                if (b == printInside)
                {
                   Dimension od = c.getSize(); //Object size
                   Dimension pd = prnJob.getPageDimension(); //Page size
                   prnGr.translate((pd.width-od.width)/2, (pd.height-od.height)/2);
                   //c.printAll(prnGr);
                   c.print(prnGr);
                   prnGr.dispose(); //Prints here
                   prnJob.end(); //Release printer
                 }
                 else
                 if (b == printFrame)
                 {
                   Dimension od = c.getSize(); //Object size
                   Dimension pd = prnJob.getPageDimension(); //Page size
                   prnGr.translate((pd.width-od.width)/2, (pd.height-od.height)/2);
                   c.printAll(prnGr);
                   prnGr.dispose(); //Prints here
                   prnJob.end(); //Release printer
                 }
            printFrame.setEnabled(true);
            printInside.setEnabled(true);
            }
          }
         public static void main(String[] args)
         {
            try
            {
               UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
            }
            catch (Exception e)
            {
               System.err.println("Couldn't use the cross-platform look and feel: " + e);
            }
            JFrame frame = new JTP3_explicit_RTL_right();
            WindowListener l = new WindowAdapter()
            {
                public void windowClosing(WindowEvent e)
                {
                   System.exit(0);
                }
            };
            frame.addWindowListener(l);
            frame.pack();
            frame.setVisible(true);
         }
      }

      ----------------------

      WorkAround:
      ======================================================================

            bcbeck Brian Beck (Inactive)
            jbenavrasunw Jonathan Benavraham (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: