1 /*
   2  * Copyright (c) 2015, 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 /*
  25  * @test
  26  * @key headful
  27  * @bug 8001470
  28  * @summary JTextField's size is computed incorrectly when it contains Indic or Thai characters
  29  * @author Semyon Sadetsky
  30  */
  31 
  32 import javax.swing.*;
  33 import java.awt.*;
  34 
  35 public class bug8001470 {
  36 
  37     private static JFrame frame;
  38     private static JTextField textField1;
  39     private static JTextField textField2;
  40 
  41     public static void main(String[] args) throws Exception {
  42         SwingUtilities.invokeAndWait(new Runnable() {
  43             @Override
  44             public void run() {
  45                 frame = new JFrame("JTextField Test");
  46                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  47 
  48                 JPanel container = (JPanel) frame.getContentPane();
  49                 container.setLayout(new GridLayout(2,1));
  50 
  51                 textField1 = new JTextField("\u0e01");
  52                 textField2 = new JTextField("\u0c01");
  53 
  54                 container.add(textField1);
  55                 container.add(textField2);
  56                 frame.setVisible(true);
  57                 frame.pack();
  58             }
  59         });
  60         if( textField1.getHeight() < 10 || textField2.getHeight() < 10 )
  61             throw new Exception("Wrong field height");
  62         System.out.println("ok");
  63         SwingUtilities.invokeLater(new Runnable() {
  64             @Override
  65             public void run() {
  66                 frame.dispose();
  67             }
  68         });
  69     }
  70 }