JDK-4200976 : BasicColorChooserUI doesn't properly handle custom preview panel
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_2.6
  • CPU: generic,sparc
  • Submitted: 1999-01-06
  • Updated: 2000-02-24
  • Resolved: 2000-02-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 merlinFixed
Related Reports
Duplicate :  
Relates :  
Description

Name: diC59631			Date: 01/06/99


Addition -- calling colorChooser.setUI(colorChooser.getUI());
corrects the problem of having to add my own change listener.

----

If I install a custom preview panel to a JColorChooser, it is never notified of changes to the ColorSelectionModel. It looks like the
 source for BasicColorChooserUI does the notification automatically (calling JComponent.setForeground() on the panel). However, I 
have to add my own ChangeListener to the ColorSelectionModel in order for my panel to be notified.

Work around includes sample program. Comment out the addChangeListener line to see problem.
(Review ID: 48981)
======================================================================


Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin FIXED IN: merlin INTEGRATED IN: merlin
14-06-2004

WORK AROUND Name: diC59631 Date: 01/06/99 import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.colorchooser.*; public class CreateColorSamplePopup { public static void main(String args[]) { JFrame frame = new JFrame("JColorChooser Create Popup Sample"); Container contentPane = frame.getContentPane(); final JButton button = new JButton("Pick to Change Background"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color initialBackground = button.getBackground(); final JColorChooser colorChooser = new JColorChooser(initialBackground); // colorChooser.setPreviewPanel(new JPanel()); final JLabel previewLabel = new JLabel("I Love Swing", JLabel.CENTER); previewLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); ChangeListener previewListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { ColorSelectionModel model = (ColorSelectionModel)changeEvent.getSource(); previewLabel.setForeground(model.getSelectedColor()); } }; colorChooser.getSelectionModel().addChangeListener(previewListener); colorChooser.setPreviewPanel(previewLabel); // For okay button selection, change button background to selected color ActionListener okActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Color newColor = colorChooser.getColor(); if (newColor.equals(button.getForeground())) { System.out.println("Color change rejected"); } else { button.setBackground(colorChooser.getColor()); } } }; // For cancel button selection, change button background to red ActionListener cancelActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { button.setBackground(Color.red); } }; final JDialog dialog = JColorChooser.createDialog(null, "Change Button Background", true, colorChooser, okActionListener, cancelActionListener); // Wait until current event dispatching completes before showing dialog Runnable showDialog = new Runnable() { public void run() { dialog.show(); } }; SwingUtilities.invokeLater(showDialog); } }; button.addActionListener(actionListener); contentPane.add(button, BorderLayout.CENTER); frame.setSize(300, 100); frame.setVisible(true); } } ======================================================================
11-06-2004

EVALUATION New preview panel is not registered in BasicColorChooserUI. Suggested fix seems to work. mark.davidson@Eng 2000-02-14
14-02-2000

SUGGESTED FIX Suggested fix: if ( e.getPropertyName().equals( JColorChooser.PREVIEW_PANEL_PROPERTY ) ) { JComponent oldPanel = (JComponent) e.getOldValue(); JComponent newPanel = (JComponent) e.getNewValue(); if (oldPanel != null) { // fix for 4166059 chooser.remove(oldPanel); } chooser.add(newPanel, BorderLayout.SOUTH); add this------> previewPanel = newPanel; } steve.wilson@eng 1998-10-07
07-10-1998