I have a weekly schedule already generated in a JTable table. What I want is that you can either paint in the cells manually with the application running (I have not found anything about it) (and also, call a method behind) or, (as I have done so far) implement popup that contains a button to paint the cell (and those things happen behind). Unfortunately, he does not paint the cells for me, I've only managed to get him to paint me a row. I tried to implement my own getTableCellRendererComponent
but it does not work correctly.
Here I leave the code of the method:
TableCellRenderer render = new TableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table,Object value,boolean selection,boolean focused,int row,int column) {
Component c= table.getDefaultRenderer(table.getColumnClass(column)).getTableCellRendererComponent(table, value, selection, focused, row, column);
if(focused) {
c.setBackground(Color.GREEN);
}
return c;
}
};
And the code of my window
JMenuItem mntmLlegadaNueva = new JMenuItem("Llegada nueva");
mntmLlegadaNueva.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Object p=table.getValueAt(table.getSelectedRow(), 0);
String f=p.toString();
String []parts2=f.split(" ");
l.getPlanif("M");
LocalTime d=l.llegaCamionEntrada2(parts2[0],parts2[1]);
LocalTime col=LocalTime.parse(table.getColumnName(table.getSelectedColumn())+":01");
System.out.println(col);
System.out.println(d);
if(d.isAfter(col)) {
render.getTableCellRendererComponent(table, values[table.getSelectedRow()][table.getSelectedColumn()],true, false, table.getSelectedRow(),table.getSelectedColumn());
}
}
});
Unfortunately, I have worked very little with interfaces, so it is doubly difficult for me to get to the root of the problem.
If in any case, you could check in some way the color of an Excel cell from Java, it could also be valid for what I'm looking for. I want to put 3 different colors depending on the time the element arrives