Name: jbT81659 Date: 08/30/2000
OS: Win98 (English, Arabic, Hebrew)
JDK: jdk1.3.0-FCS_C
Printing Bidi text from explicit RTL JtextArea, left is broken. The printed
JTeaxtArea does not show bidi Text.
To reproduce bug:
1- Compile and run the following code
2- Press the "Print entire Frame" button
3- Compare the printed JTextArea with displayed frame
4- Note that the printed JTextArea does not show bidi text as the displayed
JTextArea.
---------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 JTA2_explicit_RTL_left extends JFrame implements ActionListener
{
JLabel l, label, label2;
JLabel whatisIt;
JButton printFrame, printInside;
JPanel panel;
JPanel p;
JTextField field;
JTextArea area;
JTextPane pane;
public JTA2_explicit_RTL_left()
{
super("JTA2_explicit_RTL_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("JTA2, explicit RTL, left");
l.setVerticalAlignment(SwingConstants.BOTTOM);
l.setFont(new Font("Lucida Sans Regular",Font.PLAIN,10));
area = new JTextArea(3,15);
area.setFont(new Font("Lucida Sans Regular",Font.PLAIN,10));
area.setLineWrap(true);
area.getDocument().putProperty(TextAttribute.RUN_DIRECTION,TextAttribute.RUN_DIRECTION_RTL);
area.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(area);
p.setPreferredSize(new Dimension(200,120));
panel.add(p);
whatisIt = new JLabel("This example prints a JTextArea, explicit RTL, left");
panel.add(printFrame);
panel.add(printInside);
panel.add(whatisIt);
panel.setPreferredSize(new Dimension(200,1900));
JScrollPane scroll = new JScrollPane(panel);
scroll.setPreferredSize(new Dimension(350,250));
getContentPane().add(scroll);
}
public void actionPerformed(ActionEvent e)
{
printFrame.setEnabled(false);
printInside.setEnabled(false);
Properties prnProp = new Properties();
PrintJob prnJob = Toolkit.getDefaultToolkit().getPrintJob(JTA2_explicit_RTL_left.this, "TEST", prnProp);
if (prnJob != null)
{
JButton b = (JButton)e.getSource();
Component c;
Graphics prnGr = prnJob.getGraphics();
c = JTA2_explicit_RTL_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 JTA2_explicit_RTL_left();
WindowListener l = new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
frame.addWindowListener(l);
frame.pack();
frame.setVisible(true);
}
}
----------------------------
WorkAround:
======================================================================