提交 ce890c55 编写于 作者: S serb

7160627: [macosx] TextArea has wrong initial size

7124213: [macosx] pack() does ignore size of a component; doesn't on the other platforms
Reviewed-by: anthony, art
上级 3bca7263
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2012, 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
......@@ -26,26 +26,27 @@
package sun.lwawt;
import java.awt.AWTException;
import java.awt.BufferCapabilities;
import java.awt.Canvas;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.peer.CanvasPeer;
import javax.swing.JComponent;
final class LWCanvasPeer extends LWComponentPeer<Component, JComponent>
implements CanvasPeer {
class LWCanvasPeer<T extends Component, D extends JComponent>
extends LWComponentPeer<T, D> implements CanvasPeer {
LWCanvasPeer(final Canvas target, PlatformComponent platformComponent) {
LWCanvasPeer(final T target, final PlatformComponent platformComponent) {
super(target, platformComponent);
}
// ---- PEER METHODS ---- //
@Override
public void createBuffers(int numBuffers, BufferCapabilities caps) {
public void createBuffers(int numBuffers, BufferCapabilities caps)
throws AWTException {
// TODO
}
......@@ -67,10 +68,20 @@ final class LWCanvasPeer extends LWComponentPeer<Component, JComponent>
}
@Override
public GraphicsConfiguration getAppropriateGraphicsConfiguration(
public final GraphicsConfiguration getAppropriateGraphicsConfiguration(
GraphicsConfiguration gc)
{
// TODO
return gc;
}
@Override
public final Dimension getPreferredSize() {
return getMinimumSize();
}
@Override
public final Dimension getMinimumSize() {
return getBounds().getSize();
}
}
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2012, 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
......@@ -185,6 +185,11 @@ final class LWCheckboxPeer
rb.setBounds(0, 0, w, h);
}
@Override
public Dimension getPreferredSize() {
return getCurrentButton().getPreferredSize();
}
@Override
@Transient
public Dimension getMinimumSize() {
......
......@@ -123,7 +123,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
// private volatile boolean paintPending;
private volatile boolean isLayouting;
private D delegate = null;
private final D delegate;
private Container delegateContainer;
private Component delegateDropTarget;
private final Object dropTargetLock = new Object();
......@@ -133,6 +133,11 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
private final PlatformComponent platformComponent;
/**
* Character with reasonable value between the minimum width and maximum.
*/
static final char WIDE_CHAR = '0';
private final class DelegateContainer extends Container {
{
enableEvents(0xFFFFFFFF);
......@@ -267,9 +272,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
}
protected final D getDelegate() {
synchronized (getStateLock()) {
return delegate;
}
return delegate;
}
protected Component getDelegateFocusOwner() {
......@@ -698,26 +701,23 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
}
@Override
public FontMetrics getFontMetrics(Font f) {
public FontMetrics getFontMetrics(final Font f) {
// Borrow the metrics from the top-level window
// return getWindowPeer().getFontMetrics(f);
// Obtain the metrics from the offscreen window where this peer is
// mostly drawn to.
// TODO: check for "use platform metrics" settings
Graphics g = getWindowPeer().getGraphics();
try {
if (g != null) {
final Graphics g = getOnscreenGraphics();
if (g != null) {
try {
return g.getFontMetrics(f);
} else {
synchronized (getDelegateLock()) {
return delegateContainer.getFontMetrics(f);
}
}
} finally {
if (g != null) {
} finally {
g.dispose();
}
}
synchronized (getDelegateLock()) {
return delegateContainer.getFontMetrics(f);
}
}
@Override
......@@ -847,31 +847,46 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
}
/**
* Should be overridden in subclasses to forward the request
* to the Swing helper component, if required.
* Determines the preferred size of the component. By default forwards the
* request to the Swing helper component. Should be overridden in subclasses
* if required.
*/
@Override
public Dimension getPreferredSize() {
// It looks like a default implementation for all toolkits
return getMinimumSize();
final Dimension size;
synchronized (getDelegateLock()) {
size = getDelegate().getPreferredSize();
}
return validateSize(size);
}
/*
* Should be overridden in subclasses to forward the request
* to the Swing helper component.
/**
* Determines the minimum size of the component. By default forwards the
* request to the Swing helper component. Should be overridden in subclasses
* if required.
*/
@Override
public Dimension getMinimumSize() {
D delegate = getDelegate();
final Dimension size;
synchronized (getDelegateLock()) {
size = getDelegate().getMinimumSize();
}
return validateSize(size);
}
if (delegate == null) {
// Is it a correct default value?
return getBounds().getSize();
} else {
synchronized (getDelegateLock()) {
return delegate.getMinimumSize();
}
/**
* In some situations delegates can return empty minimum/preferred size.
* (For example: empty JLabel, etc), but awt components never should be
* empty. In the XPeers or WPeers we use some magic constants, but here we
* try to use something more useful,
*/
private Dimension validateSize(final Dimension size) {
if (size.width == 0 || size.height == 0) {
final FontMetrics fm = getFontMetrics(getFont());
size.width = fm.charWidth(WIDE_CHAR);
size.height = fm.getHeight();
}
return size;
}
@Override
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2012, 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
......@@ -41,7 +41,7 @@ import java.util.List;
import javax.swing.JComponent;
abstract class LWContainerPeer<T extends Container, D extends JComponent>
extends LWComponentPeer<T, D>
extends LWCanvasPeer<T, D>
implements ContainerPeer
{
// List of child peers sorted by z-order from bottom-most
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2012, 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
......@@ -26,37 +26,26 @@
package sun.lwawt;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Label;
import java.awt.peer.LabelPeer;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.tools.annotation.GenerateNativeHeader;
/**
* Lightweight implementation of {@link LabelPeer}. Delegates most of the work
* to the {@link JLabel}.
*/
/* No native methods here, but the constants are needed in the supporting JNI code */
@GenerateNativeHeader
final class LWLabelPeer extends LWComponentPeer<Label, JLabel>
implements LabelPeer {
private static final int TEXT_XPAD = 5;
private static final int TEXT_YPAD = 1;
LWLabelPeer(final Label target, final PlatformComponent platformComponent) {
super(target, platformComponent);
}
@Override
protected JLabel createDelegate() {
final JLabel label = new JLabel();
label.setVerticalAlignment(SwingConstants.TOP);
return label;
return new JLabel();
}
@Override
......@@ -80,24 +69,6 @@ final class LWLabelPeer extends LWComponentPeer<Label, JLabel>
}
}
@Override
public Dimension getMinimumSize() {
int w = TEXT_XPAD;
int h = TEXT_YPAD;
final FontMetrics fm = getFontMetrics(getFont());
if (fm != null) {
final String text;
synchronized (getDelegateLock()) {
text = getDelegate().getText();
}
if (text != null) {
w += fm.stringWidth(text);
}
h += fm.getHeight();
}
return new Dimension(w, h);
}
/**
* Converts {@code Label} alignment constant to the {@code JLabel} constant.
* If wrong Label alignment provided returns default alignment.
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2012, 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
......@@ -32,10 +32,22 @@ import java.awt.event.*;
import java.awt.peer.ListPeer;
import java.util.Arrays;
final class LWListPeer
extends LWComponentPeer<List, LWListPeer.ScrollableJList>
/**
* Lightweight implementation of {@link ListPeer}.
*/
final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList>
implements ListPeer {
/**
* The default number of visible rows.
*/
private static final int DEFAULT_VISIBLE_ROWS = 4; // From java.awt.List,
/**
* This text is used for cell bounds calculation.
*/
private static final String TEXT = "0123456789abcde";
LWListPeer(final List target, final PlatformComponent platformComponent) {
super(target, platformComponent);
if (!getTarget().isBackgroundSet()) {
......@@ -134,6 +146,16 @@ final class LWListPeer
}
}
@Override
public Dimension getPreferredSize() {
return getMinimumSize();
}
@Override
public Dimension getMinimumSize() {
return getMinimumSize(DEFAULT_VISIBLE_ROWS);
}
@Override
public Dimension getPreferredSize(final int rows) {
return getMinimumSize(rows);
......@@ -142,18 +164,28 @@ final class LWListPeer
@Override
public Dimension getMinimumSize(final int rows) {
synchronized (getDelegateLock()) {
final int margin = 2;
final int space = 1;
// TODO: count ScrollPane's scrolling elements if any.
final FontMetrics fm = getFontMetrics(getFont());
final int itemHeight = (fm.getHeight() - fm.getLeading()) + (2 * space);
return new Dimension(20 + (fm == null ? 10 * 15 : fm.stringWidth("0123456789abcde")),
(fm == null ? 10 : itemHeight) * rows + (2 * margin));
final Dimension size = getCellSize();
size.height *= rows;
// Always take vertical scrollbar into account.
final JScrollBar vbar = getDelegate().getVerticalScrollBar();
size.width += vbar != null ? vbar.getMinimumSize().width : 0;
// JScrollPane and JList insets
final Insets pi = getDelegate().getInsets();
final Insets vi = getDelegate().getView().getInsets();
size.width += pi.left + pi.right + vi.left + vi.right;
size.height += pi.top + pi.bottom + vi.top + vi.bottom;
return size;
}
}
private Dimension getCellSize() {
final JList<String> jList = getDelegate().getView();
final ListCellRenderer<? super String> cr = jList.getCellRenderer();
final Component cell = cr.getListCellRendererComponent(jList, TEXT, 0,
false, false);
return cell.getPreferredSize();
}
private void revalidate() {
synchronized (getDelegateLock()) {
getDelegate().getView().invalidate();
......@@ -165,10 +197,10 @@ final class LWListPeer
private boolean skipStateChangedEvent;
private DefaultListModel<Object> model =
new DefaultListModel<Object>() {
private final DefaultListModel<String> model =
new DefaultListModel<String>() {
@Override
public void add(final int index, final Object element) {
public void add(final int index, final String element) {
if (index == -1) {
addElement(element);
} else {
......@@ -181,7 +213,7 @@ final class LWListPeer
ScrollableJList() {
getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
final JList<Object> list = new JListDelegate();
final JList<String> list = new JListDelegate();
list.addListSelectionListener(this);
getViewport().setView(list);
......@@ -223,11 +255,11 @@ final class LWListPeer
}
}
public JList getView() {
return (JList) getViewport().getView();
public JList<String> getView() {
return (JList<String>) getViewport().getView();
}
public DefaultListModel<Object> getModel() {
public DefaultListModel<String> getModel() {
return model;
}
......@@ -254,7 +286,7 @@ final class LWListPeer
}
}
private final class JListDelegate extends JList<Object> {
private final class JListDelegate extends JList<String> {
JListDelegate() {
super(ScrollableJList.this.model);
......@@ -272,7 +304,7 @@ final class LWListPeer
final int index = locationToIndex(e.getPoint());
if (0 <= index && index < getModel().getSize()) {
LWListPeer.this.postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,
getModel().getElementAt(index).toString(), e.getWhen(), e.getModifiers()));
getModel().getElementAt(index), e.getWhen(), e.getModifiers()));
}
}
}
......@@ -281,10 +313,10 @@ final class LWListPeer
protected void processKeyEvent(final KeyEvent e) {
super.processKeyEvent(e);
if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ENTER) {
final Object selectedValue = getSelectedValue();
final String selectedValue = getSelectedValue();
if(selectedValue != null){
LWListPeer.this.postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,
selectedValue.toString(), e.getWhen(), e.getModifiers()));
selectedValue, e.getWhen(), e.getModifiers()));
}
}
}
......
......@@ -26,7 +26,6 @@
package sun.lwawt;
import java.awt.Dimension;
import java.awt.Panel;
import java.awt.peer.PanelPeer;
......@@ -43,9 +42,4 @@ final class LWPanelPeer extends LWContainerPeer<Panel, JPanel>
public JPanel createDelegate() {
return new JPanel();
}
@Override
public Dimension getMinimumSize() {
return getBounds().getSize();
}
}
......@@ -27,7 +27,6 @@
package sun.lwawt;
import java.awt.Adjustable;
import java.awt.Dimension;
import java.awt.Scrollbar;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
......@@ -93,13 +92,6 @@ final class LWScrollBarPeer extends LWComponentPeer<Scrollbar, JScrollBar>
}
}
@Override
public Dimension getPreferredSize() {
synchronized (getDelegateLock()) {
return getDelegate().getPreferredSize();
}
}
// Peer also registered as a listener for ComponentDelegate component
@Override
public void adjustmentValueChanged(final AdjustmentEvent e) {
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2012, 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
......@@ -29,6 +29,7 @@ package sun.lwawt;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Point;
import java.awt.TextArea;
import java.awt.event.TextEvent;
......@@ -41,11 +42,22 @@ import javax.swing.ScrollPaneConstants;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
/**
* Lightweight implementation of {@link TextAreaPeer}. Delegates most of the
* work to the {@link JTextArea} inside JScrollPane.
*/
final class LWTextAreaPeer
extends LWTextComponentPeer<TextArea, LWTextAreaPeer.ScrollableJTextArea>
implements TextAreaPeer {
/**
* The default number of visible columns.
*/
private static final int DEFAULT_COLUMNS = 60;
/**
* The default number of visible rows.
*/
private static final int DEFAULT_ROWS = 10;
LWTextAreaPeer(final TextArea target,
......@@ -86,27 +98,42 @@ final class LWTextAreaPeer
return getTextComponent();
}
@Override
public Dimension getPreferredSize() {
return getMinimumSize();
}
@Override
public Dimension getMinimumSize() {
return getMinimumSize(DEFAULT_ROWS, DEFAULT_COLUMNS);
}
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
return getPreferredSize(rows, columns);
public Dimension getPreferredSize(final int rows, final int columns) {
return getMinimumSize(rows, columns);
}
@Override
public Dimension getPreferredSize(final int rows, final int columns) {
final Dimension size = super.getPreferredSize(rows, columns);
public Dimension getMinimumSize(final int rows, final int columns) {
final Dimension size = super.getMinimumSize(rows, columns);
synchronized (getDelegateLock()) {
final JScrollBar vbar = getDelegate().getVerticalScrollBar();
final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
final int scrollbarW = vbar != null ? vbar.getWidth() : 0;
final int scrollbarH = hbar != null ? hbar.getHeight() : 0;
return new Dimension(size.width + scrollbarW,
size.height + scrollbarH);
// JScrollPane insets
final Insets pi = getDelegate().getInsets();
size.width += pi.left + pi.right;
size.height += pi.top + pi.bottom;
// Take scrollbars into account.
final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
final JScrollBar vbar = getDelegate().getVerticalScrollBar();
size.width += vbar != null ? vbar.getMinimumSize().width : 0;
}
final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
size.height += hbar != null ? hbar.getMinimumSize().height : 0;
}
}
return size;
}
@Override
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2012, 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
......@@ -48,10 +48,7 @@ abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent
extends LWComponentPeer<T, D>
implements DocumentListener, TextComponentPeer, InputMethodListener {
/**
* Character with reasonable value between the minimum width and maximum.
*/
protected static final char WIDE_CHAR = 'w';
private volatile boolean firstChangeSkipped;
LWTextComponentPeer(final T target,
......@@ -95,18 +92,16 @@ abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent
*/
abstract JTextComponent getTextComponent();
public Dimension getPreferredSize(final int rows, final int columns) {
public Dimension getMinimumSize(final int rows, final int columns) {
final Insets insets;
synchronized (getDelegateLock()) {
insets = getDelegate().getInsets();
insets = getTextComponent().getInsets();
}
final int borderHeight = insets.top + insets.bottom;
final int borderWidth = insets.left + insets.right;
final FontMetrics fm = getFontMetrics(getFont());
final int charWidth = (fm != null) ? fm.charWidth(WIDE_CHAR) : 10;
final int itemHeight = (fm != null) ? fm.getHeight() : 10;
return new Dimension(columns * charWidth + borderWidth,
rows * itemHeight + borderHeight);
return new Dimension(fm.charWidth(WIDE_CHAR) * columns + borderWidth,
fm.getHeight() * rows + borderHeight);
}
@Override
......@@ -187,6 +182,7 @@ abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent
}
}
//TODO IN XAWT we just return true..
@Override
public final boolean isFocusable() {
return getTarget().isFocusable();
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2012, 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
......@@ -37,16 +37,10 @@ import java.awt.peer.TextFieldPeer;
import javax.swing.JPasswordField;
import javax.swing.text.JTextComponent;
import javax.tools.annotation.GenerateNativeHeader;
/* No native methods here, but the constants are needed in the supporting JNI code */
@GenerateNativeHeader
final class LWTextFieldPeer
extends LWTextComponentPeer<TextField, JPasswordField>
implements TextFieldPeer, ActionListener {
private static final int DEFAULT_COLUMNS = 1;
LWTextFieldPeer(final TextField target,
final PlatformComponent platformComponent) {
super(target, platformComponent);
......@@ -83,17 +77,12 @@ final class LWTextFieldPeer
@Override
public Dimension getPreferredSize(final int columns) {
return getPreferredSize(1, columns);
return getMinimumSize(columns);
}
@Override
public Dimension getMinimumSize(final int columns) {
return getPreferredSize(columns);
}
@Override
public Dimension getMinimumSize() {
return getMinimumSize(DEFAULT_COLUMNS);
return getMinimumSize(1, columns);
}
@Override
......
......@@ -310,7 +310,7 @@ public abstract class LWToolkit extends SunToolkit implements Runnable {
@Override
public CanvasPeer createCanvas(Canvas target) {
PlatformComponent platformComponent = createPlatformComponent();
LWCanvasPeer peer = new LWCanvasPeer(target, platformComponent);
LWCanvasPeer<?, ?> peer = new LWCanvasPeer<>(target, platformComponent);
targetCreatedPeer(target, peer);
peer.initialize();
return peer;
......
/*
* Copyright (c) 2012, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.ScrollPane;
import java.awt.Toolkit;
import sun.awt.SunToolkit;
/**
* @test
* @bug 7124213
* @author Sergey Bylokhov
*/
public final class ScrollPanePreferredSize {
public static void main(final String[] args) {
final Dimension expected = new Dimension(300, 300);
final Frame frame = new Frame();
final ScrollPane sp = new ScrollPane();
sp.setSize(expected);
frame.add(sp);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
sleep();
final Dimension size = frame.getSize();
if (size.width < expected.width || size.height < expected.height) {
throw new RuntimeException(
"Expected size: >= " + expected + ", actual size: " + size);
}
frame.dispose();
}
private static void sleep() {
((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
try {
Thread.sleep(500L);
} catch (InterruptedException ignored) {
}
}
}
/*
* Copyright (c) 2012, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.Toolkit;
import sun.awt.SunToolkit;
/**
* @test
* @bug 7160627
* @summary We shouldn't get different frame size when we call Frame.pack()
* twice.
* @author Sergey Bylokhov
*/
public final class TextAreaTwicePack {
public static void main(final String[] args) {
final Frame frame = new Frame();
final TextArea ta = new TextArea();
frame.add(ta);
frame.pack();
frame.setVisible(true);
sleep();
final Dimension before = frame.getSize();
frame.pack();
final Dimension after = frame.getSize();
if (!after.equals(before)) {
throw new RuntimeException(
"Expected size: " + before + ", actual size: " + after);
}
frame.dispose();
}
private static void sleep() {
((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
try {
Thread.sleep(500L);
} catch (InterruptedException ignored) {
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册