RFR: 4337898: Serializing DefaultTableCellRenderer changes colors [v2]
Alexander Zvegintsev
azvegint at openjdk.org
Mon Dec 1 07:26:50 UTC 2025
On Mon, 1 Dec 2025 06:49:27 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..
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
>
> Automate test
test/jdk/javax/swing/DefaultTableCellRenderer/DefRendererSerialize.java line 72:
> 70: table.setDefaultRenderer(table.getColumnClass(1), tcr);
> 71:
> 72: // If this try block is removed, table text remains black on white.
This comment is too far away from the try-catch block after the test update.
test/jdk/javax/swing/DefaultTableCellRenderer/DefRendererSerialize.java line 101:
> 99: System.out.println("deserialized renderer fg " + fg + " bg " + bg);
> 100: if (!(fg == destcr.getForeground()) || !(bg == destcr.getBackground())) {
> 101: throw new RuntimeException("Desrialized foreground and background color not same");
Suggestion:
throw new RuntimeException("Deserialized foreground and background color not same");
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28549#discussion_r2575913375
PR Review Comment: https://git.openjdk.org/jdk/pull/28549#discussion_r2575910014
More information about the client-libs-dev
mailing list