I have a JTable where one column displays values in the following format:
423545(50),[7568787(50)],53654656,2021947(50),[021947],2021947(50),[8021947(50)]
I am wondering if it is possible to display the values within square brackets in RED?
I have been googling around for the last few days and have found several examples showing how to set the 'background' of a cell but not really how to change the font of a cell especially not a specific part of the text.
public class myTableCellRenderer
extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
Component c =
super.getTableCellRendererComponent(table, value,
isSelected, hasFocus,
row, column);
if (column == 3) {
c.setForeground(Color.YELLOW);
c.setBackground(Color.RED);
}
return c;
}
Is it really possible to change part of the text to be a different color (i.e. the text that is within the square brackets).
Edit
The text i showed as an example is the actual text shown in the table cell (the comma separators are not representing columns). The text displayed in the cell is a comma separated string that i display on the table in column 3.
As an example the table could look like this
product_id |product_name| invoice_numbers
12 | Books | 423545(50),[7568787(50)],53654656,2021947(50),[021947],2021947(50),[8021947(50)]
323 | Videos | 423545(50),[7568787(50)],53654656,2021947(50),[021947],2021947(50),[8021947(50)]
4434 | Music | 423545(50),[7568787(50)],53654656,2021947(50),[021947],2021947(50),[8021947(50)]