0
Jtable cell selection and highlighting
Hi, I have an attached code, it working but with a little issue. I'm able to highlight a cell with blue color. What I want is after highlighting a single cell with a blue color I want to be able to un-highlight the same cell by clicking it again. For example when I highlight cell 1, it will be highlighted with blue but when I click it again it won't be un-highlighted unless I click another cell then click cell 1 again. How can I fix this problem. In the code I'm only testing cell 1 to 4. https://code.sololearn.com/cQ1cVEjne87q/?ref=app
7 Réponses
+ 2
U can set condition take one bool value and do something like this
bool isHighlight= false
If (isHighlight)
Set background blue;
isHighlight = true
else
Set background white
isHighlight = false
+ 2
But here u have tried to add colour on the bases of condition
if (value.equals(oneSValue) || value.equals(twoSValue) || value.equals(threeSValue) || value.equals(fourSValue)) {
c.setBackground(Color.BLUE);
c.setForeground(Color.WHITE);
}
else {
c.setBackground(Color.WHITE);
c.setForeground(Color.BLACK);
}
+ 1
On mouse click u have to add condition u made a separate function for background colour right
bool isHighlight = false // by default false
Button click function () {
If (isHighlight) {
Call your getTableCellRendererComponent () // set your colour
now set isHighlight to true
}
else {
Call getCellRenderComponent ()
isHighlight is false
}
0
It won't work because the code uses getTableCellRendererComponent() method
0
So how would you suggest I modify the code ?
0
I'm not getting it to work
0
Hi Oparah anord