Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4197614

PERFORMANCE: setbackground call in TableCellRender

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.2.0
    • client-libs

      This taken from comp.lang.java.gui:

      -----Original Message-----
      From: John Fisher <###@###.###OSPAM>
      Newsgroups: comp.lang.java.gui
      Date: Sunday, December 13, 1998 11:45 AM
      Subject: CPU 100%: setbackground call in TableCellRender
      >
      >The code below demonstrates the following problem on JDK 1.1.7 on Linux,
      JDK
      >1.1.7B on Win98, and JDK 1.2 on Win98, using the release version of Swing.
      >
      >The problem is that a table with multiple colors (as implemented below)
      >immediately sends the CPU usage to 100%, and slows the entire system. Note,
      >if I uncomment the line below, and comment the line following it,
      everything
      >seems to work fine. The CPU usage only goes 100% when more than one color
      is
      >displayed at once.
      >
      >I've submitted this as a bug to JavaSoft, but I was wondering if anyone has
      >had similar problems and found a workaround (or can explain to me what I
      >might be doing wrong).
      >
      >Thanks,
      >John
      >###@###.###OSPAM
      >
      >==============================================
      >
      >import java.awt.*;
      >import javax.swing.*;
      >import javax.swing.table.*;
      >
      >
      >public class JTableTest extends JFrame
      >{
      >
      >
      > public static void main(String args[]) {
      > new JTableTest();
      > }
      >
      > public JTableTest() {
      >
      > TableModel dataModel = new AbstractTableModel() {
      > public int getColumnCount() { return 10; }
      > public int getRowCount() { return 10;}
      > public Object getValueAt(int row, int col) { return new
      >Integer(row*col); }
      > };
      >
      > JTable mytable = new JTable(dataModel) {
      > public TableCellRenderer getCellRenderer(int row, int column) {
      > TableCellRenderer renderer = super.getCellRenderer(row,
      column);
      > if (row > 5) {
      > // setBackground(Color.blue);
      > setBackground(Color.red);
      > } else {
      > setBackground(Color.blue);
      > }
      > return renderer;
      > }
      > };
      >
      > JScrollPane scrollpane = new JScrollPane(mytable);
      >
      > mytable.setToolTipText(null);
      > this.getContentPane().add(mytable);
      >
      > pack();
      > show();
      > }
      >
      > }
      >

      -----Original Message-----
      From: John Bridges <###@###.###>
      Newsgroups: comp.lang.java.gui
      To: John Fisher <###@###.###OSPAM>
      Date: Monday, December 14, 1998 3:13 AM
      Subject: Re: CPU 100%: setbackground call in TableCellRender


      >Hi John,
      >
      >yup this is completely mad.
      >
      >The problem is not with the JDK per se but with the Swing1.1
      implementation.
      >
      >(see also my "Is this mad ?" posting to this group).
      >
      >The problem lies with the fact (as far as I can determine), that a bug was
      >posted about Swing that complained setting the background/foreground colors
      etc
      >did not immediately repaint the control.
      >
      >JavaSoft in their GROSS stupidity fixed this (which isn't a bug at all in
      my
      >opinion) by placing a repaint call at the end of the method if the value of
      the
      >property changes (you can try this with setFont, setBounds, blah, blah
      etc) -
      >these are in the JComponent overrides.
      >
      >If you set the Color.blue then the background (in your example) hasn't
      changed.
      >If you set it to red, then this creates a repaint call ...
      >
      >Which enter's your method determines the color has changed which causes a
      >repaint call ...
      >Which enter's your method determines the color has changed ...
      >etc
      >etc
      >
      >Daft isn't it. So the long and short of all this is. If you want to change
      >properties of a table cell renderer, it mustn't be a JComponent derivative
      (I
      >have'nt checked 1.2 they have been really dumb and moved this fix into the
      >Component class ... ).
      >
      >This is definitely a bug.
      >
      >More than a bug, its gross stupidity.
      >
      >Regards
      >
      >John

            stewilso Steve Wilson (Inactive)
            stewilso Steve Wilson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: