Integrated: 4337898: Serializing DefaultTableCellRenderer changes colors

Prasanta Sadhukhan psadhukhan at openjdk.org
Fri Jan 2 09:51:20 UTC 2026


On Fri, 28 Nov 2025 06:29:45 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

> 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.
> 
> The problem seems to stem from a call to
> `installUI `in the `writeObject()` method of `JLabel`, `DefaultTableCellRenderer`'s base class.
>  This causes the `setForeground` and `setBackground` methods to be invoked with specific colors, which turn out to be JLabel's defaults.
> Invoking these methods subsequently with parameters of null restores normal operation same as is explicitly done in `DefaultTableCellRenderer.updateUI()`
> https://github.com/openjdk/jdk/blob/195b36f90b789b64f4a0fc867c620935d609a455/src/java.desktop/share/classes/javax/swing/table/DefaultTableCellRenderer.java#L159-L162
> 
> CI run is ok..

This pull request has now been integrated.

Changeset: 2ea3c00e
Author:    Prasanta Sadhukhan <psadhukhan at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/2ea3c00e4f2a6e8c0a55039aee6fdfc8194a70a7
Stats:     151 lines in 2 files changed: 150 ins; 0 del; 1 mod

4337898: Serializing DefaultTableCellRenderer changes colors

Reviewed-by: azvegint

-------------

PR: https://git.openjdk.org/jdk/pull/28549


More information about the client-libs-dev mailing list