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

JSplitPane loses divider location when reopened via JOptionPane.createDialog() - since Java 24

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • 25
    • 24
    • client-libs

      ### Please provide a brief summary of the bug

      When a JSplitPane is embedded inside a lazily-initialized panel, and this panel is displayed using a dialog created via JOptionPane.createDialog(), the divider location is not preserved when reopening the dialog. This is a regression observed in OpenJDK 24. The issue does not occur in OpenJDK 23, where the divider location remains as the user left it.

      ### Did you test with the latest update version?

      - [x] Yes alos tested with 24.0.1

      ### Please provide steps to reproduce where possible

      Steps to Reproduce:
      - Run the test case below
      - Click "Open Dialog"
      - Move the JSplitPane divider to a different location
      - Close the dialog
      - Click "Open Dialog" again
      - The divider is reset to a new location and does not retain the previous position

      ### Test Case

      <details>
      <summary>SplitPaneResetBugOptionPane.java (click to expand)</summary>

      ```java
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.ActionEvent;

      /**
       * Reproduces a regression in OpenJDK 24:
       * JSplitPane loses divider location when reopened via JOptionPane.createDialog().
       *
       * On OpenJDK 23: divider location is preserved across dialog openings.
       * On OpenJDK 24: divider location is lost and resets on each reopening.
       */
      public class SplitPaneResetBugOptionPane {

          private static JPanel lazyPanel;
          private static JSplitPane splitPane;

          public static void main(String[] args) {
              SwingUtilities.invokeLater(SplitPaneResetBugOptionPane::createAndShowUI);
          }

          private static void createAndShowUI() {
              JFrame frame = new JFrame("JSplitPane Divider Location");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              JButton openDialogButton = new JButton(new AbstractAction("Open Dialog") {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                      openDialogFromOptionPane(frame);
                  }
              });

              frame.getContentPane().add(openDialogButton, BorderLayout.CENTER);
              frame.setSize(400, 100);
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
          }

          private static void openDialogFromOptionPane(JFrame parent) {
              if (lazyPanel == null) {
                  System.out.println("Creating lazy panel...");
                  lazyPanel = new JPanel(new BorderLayout());

                  JPanel left = new JPanel();
                  left.setBackground(Color.ORANGE);
                  JPanel right = new JPanel();
                  right.setBackground(Color.LIGHT_GRAY);

                  splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
                  splitPane.setPreferredSize(new Dimension(400, 200));

                  // Set initial divider location — not preserved across dialog openings in OpenJDK 24
                  splitPane.setDividerLocation(120);

                  lazyPanel.add(splitPane, BorderLayout.CENTER);
              }

              JOptionPane optionPane = new JOptionPane(lazyPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION);
              JDialog dialog = optionPane.createDialog(parent, "SplitPane Dialog (JOptionPane)");
              dialog.setModal(true);
              dialog.setVisible(true);
          }
      }
      ```

      ### Expected Results

      When reopening the dialog, the divider location should remain where the user left it.


      ### Actual Results

      Each time the dialog is reopened, the JSplitPane resets to a new divider location, discarding the previous state.

      ### What Java Version are you using?

      openjdk 24 2025-03-18 OpenJDK Runtime Environment Temurin-24+36 (build 24+36) OpenJDK 64-Bit Server VM Temurin-24+36 (build 24+36, mixed mode, sharing)

      ### What is your operating system and platform?

      Windows 10 22H2

            psadhukhan Prasanta Sadhukhan
            karianna Martijn Verburg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: