1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* 24 * @test 25 * @bug 8191428 26 * @summary Verifies if text view is not borken into multiple lines 27 * @run main/othervm -Dsun.java2d.uiScale=1.2 TestGlyphBreak 28 */ 29 30 import java.awt.FontMetrics; 31 import javax.swing.JButton; 32 import javax.swing.JFrame; 33 import javax.swing.SwingUtilities; 34 35 public class TestGlyphBreak { 36 37 static JFrame f; 38 static int btnHeight; 39 static FontMetrics fm; 40 41 public static void main(String[] args) throws Exception { 42 43 SwingUtilities.invokeAndWait(() -> { 44 45 String str = "<html><font size=2 color=red><bold>Three!</font></html>"; 46 JButton b = new JButton(); 47 b.setText(str); 48 49 f = new JFrame(); 50 f.add(b); 51 f.pack(); 52 f.setVisible(true); 53 btnHeight = b.getHeight(); 54 fm = b.getFontMetrics(b.getFont()); 55 56 }); 57 58 try { 59 Thread.sleep(2000); 60 } catch (InterruptedException ex) { 61 } 62 SwingUtilities.invokeAndWait(() -> f.dispose()); 63 System.out.println("metrics getHeight " + fm.getHeight() + 64 " button height " + btnHeight); 65 66 // Check if text is broken into 2 lines, in which case button height 67 // will be twice the string height 68 if (btnHeight > 2*fm.getHeight()) { 69 throw new RuntimeException("TextView is broken into different lines"); 70 } 71 } 72 }