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

SWT_AWT focus issues when a dialog is shown/disposed, on X11

    XMLWordPrintable

Details

    • b78
    • generic
    • linux

    Description

      This issue is reported against SWT:

      https://bugs.eclipse.org/bugs/show_bug.cgi?id=207223

      In a few words, they embed a text area into an SWT container using SWT_AWT bridge, and then show a dialog with yet another text area. Sometimes, when the dialog is shown, one text area or another are not editable as if the frame/dialog didn't have the input focus.

      The source code to reproduce the problem is here:

      import java.awt.BorderLayout;
      import java.awt.FlowLayout;
      import java.awt.Frame;
      import java.awt.Panel;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.JButton;
      import javax.swing.JDialog;
      import javax.swing.JPanel;
      import javax.swing.JRootPane;
      import javax.swing.JScrollPane;
      import javax.swing.JTextArea;

      import org.eclipse.swt.SWT;
      import org.eclipse.swt.awt.SWT_AWT;
      import org.eclipse.swt.layout.FillLayout;
      import org.eclipse.swt.widgets.Composite;
      import org.eclipse.swt.widgets.Display;
      import org.eclipse.swt.widgets.Shell;

      public class PR207223 {
          public static void main(String[] args) {
              Display display = new Display();
              Shell shell = new Shell(display);

              shell.setLayout(new FillLayout());
              Composite composite = new Composite(shell, SWT.EMBEDDED);
              final Frame frame = SWT_AWT.new_Frame(composite);


              Panel panel2 = new Panel(new BorderLayout());
      // JPanel panel1 = new JPanel();
              JRootPane panel1= new JRootPane();
              panel2.add(panel1);
              frame.setLayout(new FlowLayout());

              panel1.setLayout(new FlowLayout());
              JButton button = new JButton("Launch dlg");
              final JDialog dlg = new JDialog(frame);
              //
              dlg.setModal(true);
              dlg.setTitle("Swing JDialog");
              button.addActionListener( new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      JPanel panel = new JPanel();
                      panel.setLayout(new FlowLayout());
                      JTextArea txtarea = new JTextArea(5, 20);
                      JScrollPane scrollpane = new JScrollPane(txtarea);
                      panel.add(scrollpane);

                      JButton button = new JButton("Close");
                      button.addActionListener( new ActionListener() {
                          public void actionPerformed(ActionEvent e) {
                              dlg.dispose();
                          }
                      });
                      panel.add(button);

                      dlg.getContentPane().add(panel);
                      dlg.pack();
                      dlg.setVisible(true);
                  }
              });
              panel1.add(button);

              JTextArea txtarea = new JTextArea(5, 20);
              JScrollPane scrollpane = new JScrollPane(txtarea);
              panel1.add(scrollpane);

              frame.add(panel2);
              frame.add(panel1);

              shell.setSize(400, 200);
              shell.setText("SWT_AWT main window");
              shell.open();
              while(!shell.isDisposed()) {
                  if(!display.readAndDispatch()) {
                      display.sleep();
                  }
              }
              display.dispose();
          }
      }

      Attachments

        Issue Links

          Activity

            People

              ant Anton Tarasov (Inactive)
              art Artem Ananiev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: