Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JCheckBox/8032667/bug8032667.java
32273 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import java.awt.BorderLayout;23import java.awt.Canvas;24import java.awt.Dimension;25import java.awt.Graphics;26import java.awt.Graphics2D;27import java.awt.Image;28import java.awt.image.BufferedImage;29import javax.swing.JApplet;30import javax.swing.JCheckBox;31import javax.swing.JComponent;32import javax.swing.SwingUtilities;3334/* @test35* @bug 803266736* @summary [macosx] Components cannot be rendered in HiDPI to BufferedImage37* @run applet/manual=yesno bug8032667.html38*/39public class bug8032667 extends JApplet {4041static final int scale = 2;42static final int width = 130;43static final int height = 50;44static final int scaledWidth = scale * width;45static final int scaledHeight = scale * height;4647@Override48public void init() {49SwingUtilities.invokeLater(new Runnable() {5051@Override52public void run() {5354final Image image1 = getImage(getCheckBox("Deselected", false));55final Image image2 = getImage(getCheckBox("Selected", true));5657Canvas canvas = new Canvas() {5859@Override60public void paint(Graphics g) {61super.paint(g);62g.drawImage(image1, 0, 0, scaledWidth, scaledHeight, this);63g.drawImage(image2, 0, scaledHeight + 5,64scaledWidth, scaledHeight, this);65}66};6768getContentPane().add(canvas, BorderLayout.CENTER);69}70});71}7273static JCheckBox getCheckBox(String text, boolean selected) {74JCheckBox checkBox = new JCheckBox(text);75checkBox.setSelected(selected);76checkBox.setSize(new Dimension(width, height));77return checkBox;78}7980static Image getImage(JComponent component) {81final BufferedImage image = new BufferedImage(82scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);83final Graphics g = image.getGraphics();84((Graphics2D) g).scale(scale, scale);85component.paint(g);86g.dispose();8788return image;89}90}919293