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

GroupLayout incorrect layout with large JTextArea

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 8u45, 8u60, 9
    • client-libs
    • b68
    • x86
    • windows_7

        FULL PRODUCT VERSION :
        java version "1.8.0_45"
        Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
        Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        A DESCRIPTION OF THE PROBLEM :
        GroupLayout of JPanel that contains a JScrollPane, that contains a JTextArea; and a JButton. When the height of the JTextArea is very large, GroupLayout fails to correctly lay out the JScrollPane and JButton within the panel.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Set TEXT_HEIGHT = 32800 in attached code.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        JButton is visible
        ACTUAL -
        JButton is not visible

        REPRODUCIBILITY :
        This bug can be reproduced always.

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

        public class GroupLayoutBug {
        private static final int TEXT_HEIGHT = 32700;
        // If the value of TEXT_HEIGHT is changed to 32800
        // "button" disappears
        // private static final int TEXT_HEIGHT = 32800;

        public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 600);
        JPanel panel = new JPanel();
        JTextArea text = new JTextArea();
        text.setMinimumSize(new Dimension(1000, TEXT_HEIGHT));
        text.setPreferredSize(new Dimension(1000, TEXT_HEIGHT));
        JScrollPane scroll = new JScrollPane(text);
        JButton button = new JButton("OK");
        GroupLayout layout = new GroupLayout(panel);
        layout.setHorizontalGroup(
        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addComponent(scroll)
        .addComponent(button));
        layout.setVerticalGroup(
        layout.createSequentialGroup()
        .addComponent(scroll)
        // Alternatively, if TEXT_HEIGHT is 32800, the max height of
        // "scroll" can be changed to fix the layout
        // .addComponent(scroll, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, 20000)
        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(button));
        panel.setLayout(layout);
        frame.getContentPane().add(panel, BorderLayout.CENTER);
        frame.setVisible(true);
        }
        }
        ---------- END SOURCE ----------

              ssadetsky Semyon Sadetsky (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: