I have a JXTreeTable and I have implements a custom Renderer.
So I have this code:
public class CustomTreeTableSpeseXCategoriaSpese extends JLabel implements TreeCellRenderer, TableCellRenderer {
/**
*
*/
private static final long serialVersionUID = 4842418316518803090L;
private Font fontTotale = new Font("Verdana", Font.BOLD, 12);
private Font fontNegativo = new Font("Verdana", Font.BOLD, 12);
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
setOpaque(true);
setHorizontalAlignment(SwingConstants.RIGHT);
if (row== table.getRowCount()-1) {
setForeground(Color.BLACK);
setBackground( Color.RED );
setFont(fontTotale);
}else if(row != table.getRowCount() && column !=3){
setForeground( Color.BLACK );
setBackground(new Color(200, 200, 200));
setFont(UtilitySwing.getTableFont());
}else if(row != table.getRowCount()-1 && column ==3){
//verifico il valore se negativo rosso
//se positivo blu
String valore = value.toString();
if(valore.startsWith("-")){
setForeground(Color.red);
setFont(fontNegativo);
}else{
setForeground(Color.blue);
setFont(fontNegativo);
}
}
setText(value != null ? value.toString() : "<null>");
return this;
}
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
setOpaque(true);
if (row== tree.getRowCount()-1) {
setForeground(Color.BLACK);
setOpaque(true);
setBackground( Color.RED );
setFont(fontTotale);
}else if(row != tree.getRowCount()){
setForeground( Color.BLACK );
setBackground(new Color(200, 200, 200));
setOpaque(true);
setFont(UtilitySwing.getTableFont());
}
setText(value != null ? value.toString() : "<null>");
return this;
}
}
This is the code to create a JXTreeTable:
public JTreeTable(){
JXTreeTable talbe = new JXTreeTable();
talbe .setTreeTableModel(new RandomTextTreeTableModel(listaConti));
talbe .setDefaultRenderer(Object.class, new CustomTreeTableSpeseXCategoriaSpese());
talbe .setTreeCellRenderer(new CustomTreeTableSpeseXCategoriaSpese());
}
If I try to run this code I can show this:
If I try to open thi first Node I can see this:
I want this: 1) Show the complete text 2) How you can see, from the images, I want to set background color gray at all first column. How can I fixed it?
EDIT
The post is not duplicate because in the segnalation post there is JTree but in my post, I have JXTreeTable, it is different