JDK-4855671 : REGRESSION 1.4: Incorrect layout in JOptionPane when using custom component
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1,1.4.1_02,1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-04-29
  • Updated: 2003-06-05
  • Resolved: 2003-06-05
Related Reports
Duplicate :  
Description

Name: jk109818			Date: 04/29/2003


FULL PRODUCT VERSION :
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)


FULL OS VERSION :
Microsoft (R) Windows
Version 5.0 (Build 2195: Service Pack 3)
Copyright (c) 1981-1999 Microsoft Corp.

A DESCRIPTION OF THE PROBLEM :
When I use a custom component to render a label with multiple lines
(essentially this is just a text area) The component is incorrectly sized and
laid out. This was ok for previous releases

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the below code and run on jre 1.4.1_02

EXPECTED VERSUS ACTUAL BEHAVIOR :
A JOptionPane should be displayed correctly sized (as it is in 1.3.1_06)
Dialog appears incorrectly sized and laid out

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.plaf.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;


/**
 * Interface to define ant look and feel colours
 *
 * @author Krystan Honour
 * @version 1.0
 */
interface AntLookSettings extends PlasmonLookSettings {
    /** panel colour for the Ant system*/
    Color ANT_PANEL_BACKGROUND = PLASMON_PURPLE;
    /** panel colour for the Ant system*/
    Color ANT_PANEL_FOREGROUND = PLASMON_WHITE;
    /** button colour for Ant system*/
    Color ANT_BUTTON_FOREGROUND = PLASMON_WHITE;
    /** button colour for Ant system*/
    Color ANT_BUTTON_BACKGROUND = PLASMON_PURPLE;
    /** Label colour for Ant system*/
    Color ANT_LABEL_FOREGROUND = PLASMON_WHITE;
    /** Label colour for Ant system*/
    Color ANT_LABEL_BACKGROUND = PLASMON_PURPLE;
    /** viewport colour for Ant system*/
    Color ANT_VIEWPORT_FOREGROUND = PLASMON_WHITE;
    /** viewport colour for Ant system*/
    Color ANT_VIEWPORT_BACKGROUND = PLASMON_PURPLE;
    /** scrollbar color for ant system*/
    Color ANT_SCROLLBAR_BACKGROUND = PLASMON_PURPLE;
    /** scrollbar track color for ant system*/
    Color ANT_SCROLLBAR_TRACK = PLASMON_PURPLE;
    /** Textpane background color*/
    Color ANT_TEXTPANE_BACKGROUND = PLASMON_PURPLE;
    /** Bold label font */
    Font ANT_BOLD_LABEL_FONT = new java.awt.Font("Dialog", Font.BOLD, 14);
    /** Disabled label foregrouns*/
    Color ANT_LABEL_DISABLED_FOREGROUND = new Color(102,102,102);


    // inner class
    class CheckBoxToggleIcon implements Icon {
        /** Main constructor*/
        public CheckBoxToggleIcon () {}
        
        /**
         * Method to actually paint the icon
         *
         * @param comp the component to paint
         * @param g the graphics object
         * @param x the x co-ord of the rectangle
         * @param y the y co-ord of the rectangle
         */
        public void paintIcon (Component comp, Graphics g, int x, int y)
        {
            final int redValue = 102;
            final int greenValue = 102;
            final int blueValue = 102;
            final AbstractButton b = (AbstractButton) comp;
            final ButtonModel model = b.getModel();
            final boolean isSelected = model.isSelected();
            final int width = getIconWidth();
            final int height = getIconHeight();

            if (comp.isEnabled()) {
                g.setColor (PLASMON_YELLOW);
            }
            else {
                g.setColor(new Color(redValue, greenValue, blueValue));
            }

            if ( isSelected )
            {
                g.fillRect (x, y, width, height );
            }
            else {
                g.drawRect (x, y, width, height);
            }
        }

        /**
         * Returns the icon width
         *
         * @return the icon width
         */
        public int getIconWidth() {
            final int width = 10;

            return width;
        }


        /**
         * Returns the icon height
         *
         * @return the icon height
         */
        public int getIconHeight() {
            final int height = 10;

            return height;
        }
    }
}

interface PlasmonLookSettings {
    /** Plasmon company purple, which is equiv to pantone 295*/
    public final static Color PLASMON_PURPLE = new Color(0,56,107);
    /** Just plain white*/
    public final static Color PLASMON_WHITE = Color.white;
    /** Plasmon company yellow, which is equiv to pantone 115*/
    public final static Color PLASMON_YELLOW = new Color(249,224,76);
}



/*
 * $Header$
 *
 * Copyright 1999-current-year by Plasmon Data Systems Ltd
 * Whiting Way, Melbourn, Hertfordshire, SG8 6EN, England
 * All rights reserved.
 *
 * $Revision$
 * Created by: Krystan Honour
 */

public class TestOption implements AntLookSettings {

    public static final String WARNING_MESSAGE = "Changing library configuration\n"
        + "may cause problems with your\n"
        + "storage management software\n\n"
        + "         Are you sure ?";

    public TestOption()
    {
       try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            UIManager.put("Button.background", new ColorUIResource(ANT_BUTTON_BACKGROUND));
            UIManager.put("Button.foreground", new ColorUIResource(ANT_BUTTON_FOREGROUND));
            UIManager.put("Label.background", new ColorUIResource(ANT_LABEL_BACKGROUND));
            UIManager.put("Label.foreground", new ColorUIResource(ANT_LABEL_FOREGROUND));
            UIManager.put("Label.font", new FontUIResource(ANT_BOLD_LABEL_FONT));
            UIManager.put("Label.disabledForeground", new ColorUIResource(ANT_LABEL_DISABLED_FOREGROUND));
            UIManager.put("Panel.background", new ColorUIResource(ANT_PANEL_BACKGROUND));
            UIManager.put("Panel.foreground", new ColorUIResource(ANT_PANEL_FOREGROUND));
            UIManager.put("Viewport.foreground", new ColorUIResource(ANT_VIEWPORT_FOREGROUND));
            UIManager.put("Viewport.background", new ColorUIResource(ANT_VIEWPORT_BACKGROUND));
            UIManager.put("ScrollBar.background", new ColorUIResource(ANT_SCROLLBAR_BACKGROUND));
            UIManager.put("ScrollBar.track", new ColorUIResource(ANT_SCROLLBAR_TRACK));
            UIManager.put("ScrollPane.background", new ColorUIResource(ANT_SCROLLBAR_BACKGROUND));
            UIManager.put("OptionPane.background", new ColorUIResource(ANT_BUTTON_BACKGROUND));

        }
        catch (Exception e) {
            e.printStackTrace();
        }

        javax.swing.JOptionPane.showMessageDialog(null,
                new MultilineLabel(WARNING_MESSAGE),
                "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
    }

    public static void main(String[] args) {
        new TestOption();
    }
}



/**
 * Class written to simulate a multilinelabel
 *
 * @author Krystan Honour
 * @version 1.0
 */
class MultilineLabel extends JTextArea {
    /**
     * Constructor for the label
     *
     * param s The string to appear in the label
     */
    public MultilineLabel(String s) {
        super(s);
    }

    /**
     * Method to update the UI
     */
    public void updateUI() {
        super.updateUI();

        // turn on wrapping and disable editing and highlighting

        setLineWrap(true);
        setWrapStyleWord(true);
        setHighlighter(null);
        setEditable(false);

        // Set the text area's border, colors and font to
        // that of a label

        LookAndFeel.installBorder(this, "Label.border");

        LookAndFeel.installColorsAndFont(this,
                                        "Label.background",
                                        "Label.foreground",
                                        "Label.font");
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None known at this time

Release Regression From : 1.3.1_06
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 182926) 
======================================================================

Comments
EVALUATION will work on this for the next release Name: anR10225 Date: 06/05/2003 The matter is incorrect preferred height calculation when JTextArea wraps lines. ======================================================================
11-06-2004

WORK AROUND Name: anR10225 Date: 06/05/2003 Turn off the line wrapping for MultilineLabel. ======================================================================
11-06-2004