Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8366215

JComboBox popup width issue with AbsoluteLayout

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • client-libs

      ADDITIONAL SYSTEM INFORMATION :
      java version "23.0.1" 2024-10-15
      Java(TM) SE Runtime Environment (build 23.0.1+11-39)
      Java HotSpot(TM) 64-Bit Server VM (build 23.0.1+11-39, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      JComboBox popup width does not expand properly when using AbsoluteLayout and custom cell rendering (see attached example). It would be desirable that JComboBox could expand properly independently of the Layout.

      ----------- BEGIN SOURCE -----------
      import javax.swing.*;
      import java.awt.*;

      public class ComboBoxBugExample {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(() -> {
                  JFrame frame = new JFrame("Bug Example");
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.setLayout(null);

                  JComboBox<String> comboBox = new JComboBox<>(new String[]{
                          "Short",
                          "A much longer item to test",
                          "The longest item in the combo box"
                  });

                  comboBox.setBounds(50, 50, 150, 30);
                  comboBox.setPrototypeDisplayValue("The longest item in the combo box");

                  frame.add(comboBox);
                  frame.setSize(400, 300);
                  frame.setVisible(true);
              });
          }
      }
      ----------- END SOURCE -----------

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: