Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8208743

JDialog with JTextArea can't accept focus when setResizable(false) called

    XMLWordPrintable

Details

    Description

      ADDITIONAL SYSTEM INFORMATION :
      java version "11-ea" 2018-09-25
      Java(TM) SE Runtime Environment 18.9 (build 11-ea+23)
      Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11-ea+23, mixed mode)

      OS: Mac OS High Sierra 10.13.6 (17G65)

      A DESCRIPTION OF THE PROBLEM :
      When a JDialog containing a JTextArea is created and setResizable(false) is called, the dialog won't accept focus and no text can be entered in the text area (command-tab or mouse click events both fail to focus the dialog).

      When the call to JDialog.setResizable(false) is removed, I can focus on the dialog and enter text as usual.

      REGRESSION : Last worked in version 10.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile and run the attached source code
      2. Click the button labeled "Press the button"
      3. Attempt to focus on the dialog that appears and enter text

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It should be possible to focus on the dialog and enter text
      ACTUAL -
      It is not possible to enter text and the dialog title appears greyed out, suggesting that it's not focused

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import javax.swing.border.EmptyBorder;
      import java.awt.*;

      public class DialogFocus extends JFrame {


          public DialogFocus() {
              setTitle("This is a frame");
              setSize(300, 200);
              JPanel panel = new JPanel();
              panel.setPreferredSize(new Dimension(300, 200));
              JButton button = new JButton("Press the button");
              button.addActionListener(e -> showDialog());

              panel.add(button);
              add(panel);
              setLocationRelativeTo(null);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
          }

          private void showDialog() {
              DialogWithTextField dialog = new DialogWithTextField(this);
              dialog.setVisible(true);
          }

          public static void main(String[] args) {
              EventQueue.invokeLater(() -> {
                  DialogFocus frame = new DialogFocus();
                  frame.pack();
                  frame.setVisible(true);
              });
          }


          private class DialogWithTextField extends JDialog {
              DialogWithTextField(Frame owner) throws HeadlessException {
                  super(owner);
                  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("Type or paste text:");
                  topLabel.setOpaque(false);

                  topPanel.add(topLabel, BorderLayout.CENTER);
                  mainPanel.add(topPanel, BorderLayout.NORTH);
                  final TextPanel textPanel = new TextPanel(80);

                  mainPanel.add(textPanel, BorderLayout.CENTER);

                  getContentPane().setLayout(new BorderLayout());
                  mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
                  getContentPane().add(mainPanel, BorderLayout.CENTER);
                  setTitle("A Dialog with a text area");
                  pack();
                  setLocationRelativeTo(getOwner());
                  this.setResizable(false);
              }
          }

          private class TextPanel extends JPanel {
              TextPanel(int charactersPerLine) {
                  JTextArea textArea = new JTextArea(20, charactersPerLine);
                  textArea.setWrapStyleWord(false);
                  textArea.setLineWrap(true);
                  textArea.setEditable(true);
                  setLayout(new BorderLayout());
                  final JScrollPane textScroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
                  add(textScroll, BorderLayout.CENTER);
              }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Get rid of the setResizable() call.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              mhalder Manajit Halder (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: