-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
1.4.0
-
generic
-
generic
Name: jbT81659 Date: 10/15/2001
OS: all tested platforms
JDK:jdk1.4.0-beta3-b83
Test Case: jTable_RTL.java
In this test case, the method setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
was applieed to JTable to set the ComponentOrientation of JTable to right to left.
While JTable header cells respected this method, the all remining part of JTable( JTable body) was
oriented LEFT_TO_RIGHT.
To reproduce this bug:
1- Compile and run the following test case under any OS (i.e RedHat Linux 7.1)
2- Verify a frame containg a JTable is displayed
3- Enlarge/Maximize the frame
4- Note that JTable Header is displayed at the right end of the JFrame
5- Note that the body of JTable is still displayed at the left end of the frame
----------------------------------Code---------------
/*
$Header: /home-bazelet/sun/src/javaLab/JDK1.4/ComponentOrientation/standard_Test_Cases/kuku/jTable_RTL.java,v 1.1 2001/10/10 12:33:55 isam Exp $
*/
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import java.util.*;
import java.awt.event.*;
public class jTable_RTL
{
TableColumn cColumn, vColumn, nColumn;
TableModel dataModel;
JTable tableView;
JComboBox comboBox;
public jTable_RTL()
{
JFrame frame = new JFrame("JTable with RTL CO ");
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {System.exit(0);}});
final String[] names = { "Header1", "Header2", "Header3", "Header4" };
final Object[][] data =
{
{
"\u0645\u062b\u0627\u0644",
"\u05e9\u05e0\u05d4\u0020\u05d9\u05e4\u05d4",
"\u0069\u0073\u0020\u0067\u0072\u0065\u0065\u006e",
new Integer(2), new Boolean(true)
},
{
"\u0645\u062b\u0627\u0644",
"\u05d6\u05d5\u0020\u05e9\u05e0\u05d4\u0020\u05d9\u05e4\u05d4",
"\u0661\u0669\u0665\u0668\u0020\u0031\u0039\u0035\u0038",
new Integer(99),
new Boolean(false)
},
{
"\u0645\u062b\u0627\u0644",
"\u05d6\u05d5\u0020\u05e9\u05e0\u05d4\u0020\u05d9\u05e4\u05d4",
"Green", new Integer(838), new Boolean(false)
},
{
"\u0645\u062b\u0627\u0644",
"\u05d6\u05d5\u0020\u05e9\u05e0\u05d4\u0020\u05d9\u05e4\u05d4",
"\u0661\u0669\u0665\u0668\u0020\u0031\u0039\u0035\u0038",
new Integer(8),
new Boolean(true)
},
{
"\u0645\u062b\u0627\u0644",
"\u05d6\u05d5\u0020\u05e9\u05e0\u05d4\u0020\u05d9\u05e4\u05d4",
"\u0661\u0669\u0665\u0668\u0020\u0031\u0039\u0035\u0038",
new Integer(3),
new Boolean(false)
},
{
"\u0645\u062b\u0627\u0644",
"\u05d6\u05d5\u0020\u05e9\u05e0\u05d4\u0020\u05d9\u05e4\u05d4",
"\u0069\u0073\u0020\u0067\u0072\u0065\u0065\u006e",
new Integer(21),
new Boolean(false)
},
{
"\u0645\u062b\u0627\u0644",
"\u05d6\u05d5\u0020\u05e9\u05e0\u05d4\u0020\u05d9\u05e4\u05d4",
"\u0069\u0073\u0020\u0067\u0072\u0065\u0065\u006e",
new Integer(14),
new Boolean(false)
},
};
dataModel = new AbstractTableModel()
{
public int getColumnCount()
{
return names.length;
}
public int getRowCount()
{
return data.length;
}
public Object getValueAt(int row, int col)
{
return data[row][col];
}
public String getColumnName(int column)
{
return names[column];
}
public Class getColumnClass(int c)
{
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col)
{
return true;
}
public void setValueAt(Object aValue, int row, int column)
{
System.out.println("Setting value to: " + aValue);
System.out.println();
data[row][column] = aValue;
}
};
tableView = new JTable(dataModel);
tableView.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
tableView.setFont(new Font("Lucida Sans Regular",Font.PLAIN,9));
tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
//tableView.setPreferredSize(new Dimension(200, 200));
comboBox = new JComboBox();
comboBox.setFont( new Font("Lucida Sans Regular", Font.PLAIN, 9));
comboBox.addItem("\u062a\u0641\u0627\u062d\u0020\u0623\u062d\u0645\u0631\u0020\u0643\u0628\u064a\u0631");
comboBox.addItem("\u062a\u0641\u0627\u062d\u0020\u0623\u062d\u0645\u0631\u0020\u0643\u0628\u064a\u0631");
comboBox.addItem("\u062a\u0641\u0627\u062d\u0020\u0623\u062d\u0645\u0631\u0020\u0643\u0628\u064a\u0631");
cColumn = tableView.getColumn("Header3");
cColumn.setPreferredWidth(200);
cColumn.setCellEditor(new DefaultCellEditor(comboBox));
DefaultTableCellRenderer colorColumnRenderer = new DefaultTableCellRenderer();
colorColumnRenderer.setBackground(Color.pink);
colorColumnRenderer.setToolTipText("Test");
cColumn.setCellRenderer(colorColumnRenderer);
TableCellRenderer headerRenderer = cColumn.getHeaderRenderer();
if (headerRenderer instanceof DefaultTableCellRenderer)
((DefaultTableCellRenderer)headerRenderer).setToolTipText("This is a test");
TableColumn vColumn = tableView.getColumn("Header4");
vColumn.setPreferredWidth(200);
nColumn = tableView.getColumn("Header3");
DefaultTableCellRenderer numberColumnRenderer = new DefaultTableCellRenderer()
{
public void setValue(Object value)
{
int cellValue = (value instanceof Number) ? ((Number)value).intValue() : 0;
setForeground((cellValue > 30) ? Color.black : Color.red);
setText((value == null) ? "" : value.toString());
}
};
nColumn.setPreferredWidth(200);
JScrollPane scrollpane = new JScrollPane(tableView);
scrollpane.setBorder(new BevelBorder(BevelBorder.LOWERED));
scrollpane.setPreferredSize(new Dimension(400, 400));
frame.setSize(450, 450);
//frame.pack();
frame.getContentPane().add(scrollpane);
frame.setVisible(true);
}
public static void main(String[] args)
{
new jTable_RTL();
}
}
-----------------------------------------------------
======================================================================