0
Good morning, everyone!
I’m new to the forum, and I apologize if I opened this topic in the wrong place. Well I have a huge problem with an action that I’m trying to do in Java Swing with the Jtable component, I’ve looked in several places and nothing that gives me a light!
What I would like it to work is the following, I have a Jtable with multiple results and when the user clicks on a row this row should change color indicating that it is selected (At this point I fill an object with a value, and from there, no other lines can be selected as long as this selected line is not "deselected"), and when it is re-clicked and deselected, it returns the default color. (The object that hangs the other lines is null again at this time, allowing the other line to be selected).
Well the code I was able to do until then was this:
public void mouseClicked(MouseEvent e) {
int l = table.convertRowIndexToModel(table.getSelectedRow());
int c = table.convertColumnIndexToModel(table.getSelectedColumn());
System.out.println("ROW: " + l + " | COLUMN: " + c);
Component com = table.prepareRenderer(table.getCellRenderer(l, c), l, c);
System.out.println("COMP: " + ((com.getBackground() == Color.RED) ? "É VERMELHO" : "NÃO É"));
if (((com.getBackground() == Color.RED) && (services.getMarkFocus() != null))) {
System.out.println("PRETO");
com.setBackground(Color.BLACK);
services.setMarkFocus(null);
} else if (((com.getBackground() != Color.RED) && (services.getMarkFocus() == null))) {
System.out.println("VERMELHO");
com.setBackground(Color.RED);
PlaceMark p = new PlaceMark();
p.setId(1);
services.setMarkFocus(p);
}
System.out.println("STATUS MARK: " + ((services.getMarkFocus() != null) ? true : false) +
"\nVERMELHO? " + ((com.getBackground() == Color.RED) ? true : false));
table.clearSelection();
super.mouseClicked(e);
}
This code even changes the color of the line, but the second time it pulls the line "looks" it takes the color of the line and says it is not red, being that at the first click it became red.
NOTE: I am using an Abstracttablemodel, which I made some edits to put image in the table.
Already I am in the waiting, and I hope that someone can give me a light.
Hugging...
Supermock
Welcome just a clarification, the OS not exactly a forum and yes a question and answer site, so don’t worry about posting on the "specific place". http://answall.com/tour
– rubStackOverflow
Related: How to color specific lines of a Jtable?
– Math
This question of how to color specific lines of a Jtable, does this change when the Jtable is being constructed correctly? Because what I would like to happen is that this change is at execution time.
– SuperMock
I believe so, but I thought it might be relevant. I didn’t have time to try to see your specific case.
– Math