United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6717617 Nimbus L&F: Regression - Using ComboBox border on TextField causes ClassCastException
JDK-6717617 : Nimbus L&F: Regression - Using ComboBox border on TextField causes ClassCastException

Details
Type:
Bug
Submit Date:
2008-06-21
Status:
Resolved
Updated Date:
2011-02-22
Project Name:
JDK
Resolved Date:
2008-06-26
Component:
client-libs
OS:
windows_vista,linux_ubuntu,generic
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6u10
Fixed Versions:
6u10 (b27)

Related Reports
Duplicate:

Sub Tasks

Description
There is a fairly odd use case which isn't entirely understood to be supported, but which was working and is now broken. The idea is that:

JComboBox cb = new JComboBox();
JTextField tf = new JTextField();
tf.setBorder(cb.getBorder());

Ends up throwing a ClassCastException. The problem is that the border on JComboBox under a Synth based look and feel is a SynthBorder, which maintains a reference to the UI that created it (SynthComboBoxUI in this case). When it is time to paint the border, it asks the UI for the Synth state. This ends up calling a private method on SynthComboBoxUI to determine the state. It would be reasonable to assume that such a private method in SynthComboBoxUI would only deal with SynthComboBoxUI's --- but in the above sequence this assumption is violated and a JTextField is passed to the internal SynthComboBoxUI method instead.

The fix is simply to put a class check back into SynthComboBoxUI. A more correct fix in Java 7 would be to fix SynthBorderUI so that if the UI didn't match the UI of the current component, then it wouldn't ask for the synth state (and thus avoid the problem entirely).

                                    

Comments
EVALUATION

Evaluation is as described in description
                                     
2008-06-21



Hardware and Software, Engineered to Work Together