RegisterSearchFAQ UsergroupsLog in
Dynamically change AdvancedJTable background color question

 
Reply to topic    Citra Technologies Forum Index » Technical Support - Evaluation View previous topic
View next topic

Dynamically change AdvancedJTable background color question
Author Message
dmacleod



Joined: 04 Oct 2007
Posts: 20

Post Dynamically change AdvancedJTable background color question Reply with quote
What is the best approach to dynamically update a rows background color in an AdvancedJTable?
Fri Nov 02, 2007 6:32 am View user's profile Send private message Send e-mail
support



Joined: 21 Feb 2006
Posts: 1463

Post Reply with quote
You could use a custom Style that maps rows to colors. Your style should also have a method that will change the row color.
For example:

Code:
public class MyStyle implements Style {
    Map rowColorMap = new HashMap();
    public applyStyle(...) {
        Color color = (Color) rowColorMap.get(new Integer(row));
        if (color != null) c.setBackGround(color);
    }
    public void setColor(int row, Color c) {
        rowColorMap.put(new Integer(row), c);
    }
}

MyStyle s = new MyStyle();
table.getStyleModel().addStyle(s);

//change the row color
s.setColor(5, Color.red);


I haven't tested this but it should work...
Fri Nov 02, 2007 7:11 am View user's profile Send private message
dmacleod



Joined: 04 Oct 2007
Posts: 20

Post Followup question Reply with quote
I got this to work based on your code, Thanks. One followup question, If I set the background color on row 5 for example, based on the data in row 5, then do a sort, the background color should follow the data to it's new sorted row number. Instead row 5 always has it's background color set no matter the sort order.

What is the best approach to get around this?

thanks
Fri Nov 02, 2007 9:36 am View user's profile Send private message Send e-mail
support



Joined: 21 Feb 2006
Posts: 1463

Post Reply with quote
You should pass the SortTableModel instance as parameter to the style and use SortTableModel.getSortedIndexes() to convert the row parameter passed as argument in the apply method.

For example:

Code:
public void applyStyle(...) {
   int convRow = SortTableModel.getSortedIndexes()[row];
   Color color = (Color) rowColorMap.get(new Integer(convRow));
   ....
}

Fri Nov 02, 2007 10:45 am View user's profile Send private message
Frechette



Joined: 20 Jun 2017
Posts: 1

Post Reply with quote
support wrote:
You should pass the SortTableModel instance as parameter to the https://ahappygirl.com/venapro-review-results style of Venapro and use SortTableModel.getSortedIndexes() to convert the row parameter passed as argument in the apply method.

For example:

Code:
public void applyStyle(...) {
   int convRow = SortTableModel.getSortedIndexes()[row];
   Color color = (Color) rowColorMap.get(new Integer(convRow));
   ....
}


Thanks for the example code, I used it and it worked great.
Mon Jun 26, 2017 2:53 am View user's profile Send private message
Display posts from previous:    

Reply to topic    Citra Technologies Forum Index » Technical Support - Evaluation All times are GMT - 5 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group