mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-01 19:50:05 +00:00
8079640: GroupLayout incorrect layout with large JTextArea
Reviewed-by: serb, alexsch, azvegint
This commit is contained in:
parent
243208ab2e
commit
3ef1c8d4c3
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -218,6 +218,9 @@ public class GroupLayout implements LayoutManager2 {
|
||||
|
||||
private static final int UNSET = Integer.MIN_VALUE;
|
||||
|
||||
// Maximum spring size constrain to avoid integer overflow
|
||||
private static final int INFINITE = Integer.MAX_VALUE >> 1;
|
||||
|
||||
/**
|
||||
* Indicates the size from the component or gap should be used for a
|
||||
* particular range value.
|
||||
@ -1389,7 +1392,7 @@ public class GroupLayout implements LayoutManager2 {
|
||||
}
|
||||
|
||||
int constrain(int value) {
|
||||
return Math.min(value, Short.MAX_VALUE);
|
||||
return Math.min(value, INFINITE);
|
||||
}
|
||||
|
||||
int getBaseline() {
|
||||
|
||||
99
jdk/test/javax/swing/GroupLayout/8079640/bug8079640.java
Normal file
99
jdk/test/javax/swing/GroupLayout/8079640/bug8079640.java
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/* @test
|
||||
@bug 8079640
|
||||
@summary GroupLayout incorrect layout with large JTextArea
|
||||
@author Semyon Sadetsky
|
||||
*/
|
||||
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class bug8079640 {
|
||||
|
||||
private static JFrame frame;
|
||||
private static JComponent comp2;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
frame = new JFrame("A Frame");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setUndecorated(true);
|
||||
setup(frame);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
test();
|
||||
System.out.println("ok");
|
||||
|
||||
} finally {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
frame.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void test() throws Exception {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(comp2.getLocation().getY() > frame.getHeight())
|
||||
throw new RuntimeException("GroupLayout fails: comp2 is out of the window");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
static void setup(JFrame frame) {
|
||||
JPanel panel = new JPanel();
|
||||
JComponent comp1 = new JLabel("Test Label 1");
|
||||
comp1.setMinimumSize(new Dimension(1000, 40000));
|
||||
comp1.setPreferredSize(new Dimension(1000, 40000));
|
||||
JScrollPane scroll = new JScrollPane(comp1);
|
||||
comp2 = new JLabel("Test Label 2");
|
||||
GroupLayout layout = new GroupLayout(panel);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
|
||||
.addComponent(scroll)
|
||||
.addComponent(comp2));
|
||||
layout.setVerticalGroup(
|
||||
layout.createSequentialGroup()
|
||||
.addComponent(scroll)
|
||||
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(comp2));
|
||||
panel.setLayout(layout);
|
||||
frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
frame.setSize(800, 600);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user