|
Quick Lists
|
|
Bug ID:
|
5029286
|
|
Votes
|
7
|
|
Synopsis
|
REGRESSION: JColorChooser.setPreviewPanel() does not show custom preview panel
|
|
Category
|
java:classes_swing
|
|
Reported Against
|
1.4.2
|
|
Release Fixed
|
|
|
State
|
11-Closed, duplicate of 6199676,
bug
|
|
Priority:
|
3-Medium
|
|
Related Bugs
|
5036962
,
4759306
,
6199676
|
|
Submit Date
|
08-APR-2004
|
|
Description
|
FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
FULL OS VERSION :
customer Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
With j2re1.4.2 JColorChooser does not show a custom preview panel, that was set with JColorChooser.setPreviewPanel(). Instead the default preview panel is removed and the space is left blank. This happens with code, that was perfectly working in 1.4.1_02 and prior versions. It happens with metal L&F and windows L&F. It is still possible to use the default preview panel.
I already tested this with 1.5.0 beta1 before and it seems to work if you set a JButton as the new previewPanel but fails with all other JComponents.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the given code in 1.4.1_02 and 1.4.2. The preview panel shows up with 1.4.1_02 but not with 1.4.2.
The code just constructs a JColorChooser within a JFrame and sets a custom preview panel, which is a JLabel in this case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the custom preview panel to appear on screen.
ACTUAL -
Custom preview panel does not show up, default preview panel is removed and space left blank.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error messages.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
public class JColorChooserTest extends javax.swing.JFrame {
/** Creates new form JcolorChooserTest */
public JColorChooserTest() {
initComponents();
PreviewPanel previewPanel = new PreviewPanel();
jColorChooser1.setPreviewPanel(previewPanel);
jColorChooser1.getSelectionModel().addChangeListener(previewPanel);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jColorChooser1 = new javax.swing.JColorChooser();
getContentPane().setLayout(new java.awt.FlowLayout());
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
getContentPane().add(jColorChooser1);
pack();
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new JColorChooserTest().show();
}
// Variables declaration - do not modify
private javax.swing.JColorChooser jColorChooser1;
// End of variables declaration
class PreviewPanel extends JLabel implements javax.swing.event.ChangeListener{
public PreviewPanel() {
super("This is the selected color!");
}
public void stateChanged(javax.swing.event.ChangeEvent e) {
Color newColor = jColorChooser1.getColor();
setForeground(newColor);
}
}
}
---------- END SOURCE ----------
Release Regression From : 1.4.1
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Incident Review ID: 189871)
======================================================================
|
|
Work Around
|
N/A
|
|
Evaluation
|
Seems the problem is caused by the fix for 4759306 in
BasicColorChooserUI.installPreviewPanel:
layoutSize = new BorderLayout().minimumLayoutSize(previewPanel);
if ((previewPanelHolder != null) && (chooser != null) &&
(layoutSize.getWidth() + layoutSize.getHeight() == 0)) {
chooser.remove(previewPanelHolder);
return;
}
Here minimumLayoutSize returns (0,0) for JPanel, JLabel, and non-zero
values for JButton, and so previewPanelHolder is removed from the
chooser before previewPanel is added to it.
xxxxx@xxxxx 2004-04-14
======================================================================
The reason because minimumLayoutSize in the above code returns 0,0 in
most of the cases is that this method requires the target component to
be added to the layout to calculate the required space. But even
modifying this code as:
BorderLayout layout = new BorderLayout();
layout.addLayoutComponent(previewPanel, BorderLayout.SOUTH);
Dimension layoutSize = layout.minimumLayoutSize(previewPanel);
doesn't give the desired result, because in this case the returned
minimum size of the empty JPanel is (10,10): which is not (0,0).
xxxxx@xxxxx 2004-04-23
======================================================================
The fix for 4759306 suggested users to pass an empty JPanel to
setPreviewPanel() if they wanted to remove the default preview panel
along with previewPanelHolder. This behaviour is not specified by the
javadoc, is hardly implementable in a non error prone way, and I
think, is not reasonable. I suggest to change it in the following way:
- setting a custom panel shouldn't lead to the checks of the sizes of
the panel submitted by the user,
- complete removal of the preview panel should be done upon:
setPreviewPanel(null)
The default preview panel still can be restored this way:
setPreviewPanel(ColorChooserComponentFactory.getPreviewPanel())
- after removal of the preview panel it should be possible to restore
the default panel or set a custom panel (now it's not possible)
xxxxx@xxxxx 2004-04-23
======================================================================
This bug is caused by the same reason as #6199676
closed as duplicate
xxxxx@xxxxx 2004-12-26 16:46:02 GMT
|
|
Comments
|
Submitted On 16-APR-2004
ibormann
Workaround
The evaluation seems to be right: if I set
previewPanel.setSize(previewPanel.getPreferredSize
());
before I do
jColorChooser1.setPreviewPanel(previewPanel);
then the previewPanel shows up with its correct size
with 1.4.2_03.
Submitted On 22-JUL-2004
thomas_tampe
In order to first remove the preview panel using setPreviewPanel(null); and later adding a custom one, the previewPanelHolder must be added to the chooser again.
It seems easier to hide the previewPanelHolder, if the provided custom previewPanel is null and to show it again if the custom previewPanel is not null, such as in
previewPanelHolder.setVisible(previewPanel != null);
Submitted On 29-NOV-2004
javaedt
The "setPreviewPanel" workaround works for 1.4.2 but not 1.5.0. The 1.5.0 code in 'BasicColorChooserUI.installPreviewPanel()' is looking for 'minimumLayoutSize()' > 0, so an additional workaround is to add a border with insets. To get the preview to display under both versions of Java, both workarounds should be done, like this:
previewPanel.setSize(previewPanel.getPreferredSize());
previewPanel.setBorder(BorderFactory.createEmptyBorder(0,0,1,0));
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |