I am trying to display data (combination of english and Non-english languages) using Jtable. Since i also have Non-english data i am trying to set font for each cell(jtextfield). I also want to edit data in after rendering in Jtable but i am unable to implement (ie., code in focusgained() is not being called) focus listener events on jtext fileds.
I have used the following renderer to display data in jtable with each cell as a text field
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JTextField tf=new JTextField();
if (value != null) {
if (value.startsWith("_")) {
value=value.substring(1);
tf.setFont(fntEng);
} else if (fnt_Local != null && fnt_Local.canDisplayUpTo(value.toString()) == -1) {
tf.setFont(fnt_Local);
}
setText(value.toString());
} else {
tf.setFont(fnt_Local);
tf.setText((String) value);
}
tf.setForeground(Color.BLACK);
tf.setBackground(Color.WHITE);
tf.setText(value.toString());
tf.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
JTextField tf1=(JTextField)e.getComponent();
tf1.setText("Focusgained");
}
public void focusLost(FocusEvent e) {
}
});
return tf;
}
};