Dynamically set font in a JTable cell

Hi there,

i have a JTable, and a JTCombo box containing all the system fonts available. The JTable is made up of my own class called myCell which can be seen below. I have also implemented my own custom renderer. What i would like to do is when the user selects a new system font, the text that is then typed into the JTable to be of that font. If the system font is changed again, i would like any new text to be of the new font, and the old fonts remain the same (i hope that makes sense!) Anyway, im quite stuck about this - i have tried messing around with the cellrenderer but all the text in all the cells changes to the new font. Does anyone know how to do this? many thanks, Rupz

public myCell(int aRow,int aCol,Object someValue, TreeSet somecells, String aFormula){

row = aRow;

col = aCol;

value = someValue;

expression = aFormula;

references = somecells;

}

[1072 byte] By [rupz112a] at [2007-9-30 2:23:45]
# 1

First of all the Java standard for class names us to use upper case characters for the first letter of each word. So your class should be MyCell.

Now your MyCell class need to keep the Font as one of its properties. Maybe you would override the JTable getCellEditor(...) method such that if the Font property for the cell is null, then set the cell Font to the current default Font. The renderer would then use the Font from the cell when it is non-null.

camickra at 2007-7-16 13:33:07 > top of Java-index,Archived Forums,Swing...