--- /dev/null 2018-11-30 16:41:30.000000000 +0530 +++ new/test/jdk/java/awt/Focus/NonResizableFocusableDialogTest/NonResizableFocusableDialogTest.java 2018-11-30 16:41:29.000000000 +0530 @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018, 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 + * @key headful + * @bug 8208743 8208290 + * @summary Non resizable focusable JDialog containing JTextArea is not + * focusable and not allowing text entry + * @run main NonResizableFocusableDialogTest + */ +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.awt.Robot; +import java.awt.event.KeyEvent; +import java.lang.reflect.InvocationTargetException; +import javax.swing.JDialog; +import javax.swing.SwingUtilities; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.JScrollPane; +import javax.swing.border.EmptyBorder; +import javax.swing.JLabel; + +public class NonResizableFocusableDialogTest { + private JTextArea textArea; + private JDialog jDialog; + + private void createDialogWithTextArea() { + jDialog = new JDialog(); + jDialog.setTitle("JDialog with a JTextArea"); + JPanel mainPanel = new JPanel(new BorderLayout()); + mainPanel.setOpaque(false); + + JPanel topPanel = new JPanel(new BorderLayout()); + topPanel.setBorder(new EmptyBorder(0, 5, 5, 0)); + JLabel topLabel = new JLabel("This is a automatic test"); + topLabel.setOpaque(false); + + topPanel.add(topLabel, BorderLayout.NORTH); + mainPanel.add(topPanel, BorderLayout.NORTH); + + final TextPanel textPanel = new TextPanel(40); + mainPanel.add(textPanel, BorderLayout.CENTER); + mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + + jDialog.add(mainPanel, BorderLayout.CENTER); + jDialog.pack(); + jDialog.setResizable(false); + jDialog.setVisible(true); + } + + private void enterTextInTextArea() throws InvocationTargetException, InterruptedException { + try { + Robot robot = new Robot(); + robot.delay(3000); + robot.keyPress(KeyEvent.VK_T); + robot.keyRelease(KeyEvent.VK_T); + robot.waitForIdle(); + + //verify if text is entered in text area, if not throw exception + if(!"t".equals(textArea.getText())) { + throw new RuntimeException("JTextArea is not focusable, text can't be" + + " entered in text area. TEST FAILED"); + } + } catch (AWTException e) { + throw new RuntimeException("Robot creation failed. TEST FAILED"); + } finally { + SwingUtilities.invokeAndWait(jDialog::dispose); + } + } + + public static void main(String args[]) throws Exception { + NonResizableFocusableDialogTest dialog = new NonResizableFocusableDialogTest(); + //create a JTextArea in JDialog. + SwingUtilities.invokeAndWait(dialog::createDialogWithTextArea); + //Try to enter text in JTextArea and check if text can be entered + dialog.enterTextInTextArea(); + } + + private class TextPanel extends JPanel { + TextPanel(int charactersPerLine) { + textArea = new JTextArea(20, charactersPerLine); + textArea.setEditable(true); + setLayout(new BorderLayout()); + final JScrollPane textScroll = new JScrollPane(textArea, + JScrollPane.VERTICAL_SCROLLBAR_NEVER, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + add(textScroll, BorderLayout.CENTER); + } + } +} +