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

Window.toFront() fails for iconified windows on Linux

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 23
    • 11, 17, 21
    • client-libs
    • None
    • b14
    • linux

      To reproduce:
      - run the following program,
      - when windows appear, iconify "Window 1",
      - then click the the "Bring up Window 1" button in "Window 2".
      This should bring back the other window but does not.

      A workaround is to force Frame.NORMAL state on "Window 1", but then it won't come back in the same state as before it was iconified.

      import javax.swing.*;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      public class Main {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      createAndShowGUI();
                  }
              });
          }

          private static void createAndShowGUI() {
              final JFrame frame1 = new JFrame("Window 1");
              frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame1.setSize(200, 200);
              frame1.setLocationRelativeTo(null);
              frame1.setExtendedState(JFrame.MAXIMIZED_BOTH);
              frame1.setVisible(true);

              JFrame frame2 = new JFrame("Window 2");
              frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame2.setSize(200, 200);
              frame2.setLocation(220, 200);

              JButton button = new JButton("Bring up Window 1");
              frame2.getContentPane().add(button);

              button.addActionListener(new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                      // Workaround:
                      // frame1.setExtendedState(JFrame.NORMAL);
                      frame1.toFront();
                  }
              });

              frame2.setVisible(true);
          }
      }

            mkartashev Maxim Kartashev
            mkartashev Maxim Kartashev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: