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

Printing bidi text in JTextField fails

    XMLWordPrintable

    Details

      Description



      Name: jbT81659 Date: 08/30/2000

      OS: Win98 (English, Arabic, Hebrew)
      JDK: jdk1.3.0-FCS_C

      Printing bidi text displayed in JTextField fails. Text displayed is not printed.
      To reproduce bug:
      1- Compile and run the following code
      2- To print Frame press the "Print Entire Frame" button
      3- Compare printed frame with displayed frame.
      4- Note that text displayed in JTextField is not printed.

      --------------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 JTF1_implicit_left extends JFrame implements ActionListener
      {
         JLabel l, label, label2;
         JLabel whatisIt;
         JButton printFrame, printInside;
         JTextField field;
         JTextArea area;
         JTextPane pane;
         JPanel p;
         JPanel panel;

         public JTF1_implicit_left()
         {
             super("JTF1_implicit_left");

          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 GridLayout(2,1));
          l = new JLabel("JTF1, implicit, left");
          l.setVerticalAlignment(SwingConstants.BOTTOM);
          l.setFont(new Font("Lucida Sans Regular",Font.PLAIN,10));
          field = new JTextField(30);
          field.setFont(new Font("Lucida Sans Regular",Font.PLAIN,10));
          field.setText("This is a test \u0647\u0630\u0627\u0020\u05d6\u05d4\u0020\u05d9\u05d5\u05dd\u0020\u05e0\u05e2\u05d9\u05dd\u0020\u064a\u0648\u0645\u0020\u0644\u0637\u064a\u0641");
          p.add(l);
          p.add(field);
          p.setPreferredSize(new Dimension(250,60));
          panel.add(p);
          whatisIt = new JLabel("This example prints JTextField, implicit, left");
          panel.add(printFrame);
          panel.add(printInside);
          panel.add(whatisIt);
          panel.setPreferredSize(new Dimension(200,200));
          JScrollPane scroll = new JScrollPane(panel);
          scroll.setPreferredSize(new Dimension(280,200));

          getContentPane().add(scroll);

         }
         public void actionPerformed(ActionEvent e)
         {
             printFrame.setEnabled(false);
             printInside.setEnabled(false);
             Properties prnProp = new Properties();
             PrintJob prnJob = Toolkit.getDefaultToolkit().getPrintJob(JTF1_implicit_left.this, "TEST", prnProp);
             if (prnJob != null)
             {
                JButton b = (JButton)e.getSource();
                Component c;
                Graphics prnGr = prnJob.getGraphics();
                c = JTF1_implicit_left.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.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 JTF1_implicit_left();
            WindowListener l = new WindowAdapter()
            {
                public void windowClosing(WindowEvent e)
                {
                   System.exit(0);
                }
            };
            frame.addWindowListener(l);
            frame.pack();
            frame.setVisible(true);
         }
      }
      ----------------------------------

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: