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

Serializing DefaultTableCellRenderer changes colors.

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      generic, linux

      Description

      Name: skT45625 Date: 05/12/2000


      On Windows 95:

      java version "1.2"
      HotSpot VM (1.0.1, mixed mode, build c)


      On Solaris:

      java version "1.2.1"
      Classic VM (build JDK-1.2.1-A, native threads, sunwjit)

      When a JTable using any objects of type DefaultTableCellRenderer, or
      subclasses, is serialized, the colors used to render cells in the JTable
      subsequent to the call to writeObject() are forced to the default colors for
      DefaultTableCellRenderer's immediate base class, JLabel, causing the colors
      defined in the JTable (typically black on white) to be ignored.

      I first ran across this problem under Solaris, Java version 1.2.1, and was able
      to reproduce it on Windows 95 under Java 1.2 in the process of generating the
      sample code below.

      A code sample illustrating the problem follows:

      RendererExample.java

      import javax.swing.*;
      import javax.swing.table.*;
      import java.lang.*;
      import java.util.*;
      import java.io.*;

      public class RendererExample {

         public RendererExample() {
            new RendererFrame();
         }

         public static void main (String[] args) {
            RendererExample app = new RendererExample();
         }
      }


      class RendererFrame extends JFrame {
         RendererFrame() {
            super();
            String[][] rowData = { {"1-1","1-2","1-3"},
                                   {"2-1","2-2","2-3"},
                                   {"3-1","3-2","3-3"} };

            String[] columnData = {"Column 1", "Column 2", "Column 3"};

            JTable table = new JTable(rowData, columnData);

            table.setDefaultRenderer(table.getColumnClass(1),
                                     new DefaultTableCellRenderer());

            // If this try block is removed, table text remains black on white.

            try {

               ObjectOutputStream ostream = new ObjectOutputStream(new
      ByteArrayOutputStream());
               ostream.writeObject(table.getDefaultRenderer(table.getColumnClass(1)));
            } catch (IOException ioex) {
               ioex.printStackTrace();
            }

            getContentPane().add(table);

            pack();
            setVisible(true);
         }
      }
      (Review ID: 104821)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            skondamasunw Suresh Kondamareddy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: