Hi all,
The font type of the cell is set to 'Arial Unicode MS'. While editing the cell during the runtime, the font of the cell is changed to the default font.
Thanks.
Printable View
Hi all,
The font type of the cell is set to 'Arial Unicode MS'. While editing the cell during the runtime, the font of the cell is changed to the default font.
Thanks.
How do you set the font type of the cell?
JTable uses two different components to show cell contents - a TableCellRenderer to display the contents when not being edited and a TableCellEditor to edit the contents. You need to set the font for both if you want them both to be different from the default. See Editors & Renderers.
In the particular is contained the universal...
J. Joyce
Thanks for your reply.
I found the solution. 've set the font of the Textfield.
for (int i = 0; i < jTable1.getColumnCount(); i ++) {
TableColumn col = jTable1.getColumnModel().getColumn(i);
col.setCellEditor(new MyTableCellEditor());
}
public class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor {
JComponent component = new JTextField();
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, int vColIndex) {
((JTextField)component).setText((String)value);
((JTextField)component).setFont(new java.awt.Font("Arial Unicode MS", 0, 12));
return component;
}
for (int i = 0; i < jTable1.getColumnCount(); i ++) {
TableColumn col = jTable1.getColumnModel().getColumn(i);
col.setCellEditor(new MyTableCellEditor());
col.setCellRenderer(new MyTableCellRenderer());
}
public class MyTableCellRenderer
extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (row == 0 && column == 0) {
component.setFont(new java.awt.Font("Arial Unicode MS", 0, 12));
}
else {
// Some other font.
}
return component;
}
}
If you're setting the same renderer and editor for every column, you can just call the default mutators:This simplifies and saves you creating multiple copies of renderer and editor when you only need one.Code:table.setDefaultRenderer(Object.class, new MyTableCellRenderer());
table.setDefaultEditor(Object.class, new MyTableCellEditor());
Controlling complexity is the essence of computer programming...
B. Kernighan
Thanks a lot