JDK-8050970 : The behavior of java.awt.List in jdk5 should be the same to that in JDK6,7 and 8
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0u14
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • CPU: generic
  • Submitted: 2014-07-17
  • Updated: 2015-01-20
  • Resolved: 2014-09-30
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 Other
5.0u81Fixed 5.0u85 b01Fixed
Related Reports
Relates :  
Description

In JDK5u71, When a program lays out java.awt.List by using FlowLayout,
although there is no space of preferred size in right side,
the List is placed at right side.

In JDK6u81, 7u65 and 8u11, the List is placed at next row.

TEST CASE
-----------
Test case is as follows.

--- ListTest.java --->
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ListTest extends Frame implements ActionListener {

    Button button = new Button("List.getPreferredSize()");
    List list = new List(5);
    Label label = new Label();

    public static void main(String ar[]){
        Frame f = new ListTest();
        f.setSize(350,350);
        f.setVisible(true);
    }

    ListTest(){
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });

        setLayout(new FlowLayout());
        button.addActionListener(this);
        add(button);
        list.add("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        add(list);
    }

    public void actionPerformed(ActionEvent e){
        Dimension dim = list.getPreferredSize();
        button.setBackground(Color. YELLOW);
        button.setLabel("Width:" + Double.toString(dim.getWidth()) + " 
Height:" +Double.toString( dim.getHeight()));
    }
}
<---


REPRODUCTION INSTRUCTIONS
-------------------------------
Compile ListTest.java and run "java ListTest"

EXPECTED Result
----------------
List appears under "List.getPreferredSize() " button.

ACTUAL Result
-----------------
List appears at the right side of "List.getPreferredSize() " button.

 

Comments
Root cause: Implementation of Java_sun_awt_windows_WListPeer_getMaxWidth() method calls AwtList::_UpdateMaxItemWidth instead of AwtList::_GetMaxWidth. The latter returns int value which is the maximum width of items in the list, whereas the former returns void. Thus, JNI method for getMaxWidth() returns garbage. It also explains why debug build results are quite different from release build. See also JDK-6373369 which addressed this bug for JDK 6.
24-09-2014

This came to occur in jdk5u14. I attached a file which shows the difference between 5u13 and 5u14.
23-07-2014