Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

High CPU issue due to table.setForeground() in JTable renderer

843807Jul 16 2010 — edited Jul 19 2010
Hi,

I have a JTable with a renderer to set the text color for the row if certain conditions exist.

The code below "works" although I have two issues:-

1. The command "table.setForeground(Color.BLUE);" in the code below causes 50% CPU utilisation (Win XP, service pack 3). Very strange and consistent - tested on two different PCs.

2. At times, the first column below the intended column changes color. The rest of the intended column has color set correctly.

I'm using beans binding with the table concerned so can't post the table model - I believe the binding effectively has it's own model.

Be greatful for any insight as it seems v. strange.....

Thanks,
</code>
...
...
        masterTable.setDefaultRenderer(String.class, textColour);
...
...
...

    TableCellRenderer textColour = new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus, int row, int column) {

            MailingList mL = (MailingList) queryList.get((table.convertRowIndexToModel(row)));

            table.setForeground(Color.BLACK);

            if (mL.getApplicationAppId() != null) {
                if (mL.getApplicationAppId().getSembookingsCollection() != null) {
                    Collection sB = mL.getApplicationAppId().getSembookingsCollection();
                    if (!sB.isEmpty()) {
//                        table.setForeground(Color.BLUE);  //this line causes 50% CPU utilisation ???
                    }
                }
            }


            TableCellRenderer delegate = table.getDefaultRenderer(Object.class);
            return delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        }
    };
{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 16 2010
Added on Jul 16 2010
12 comments
329 views