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

Internal Frame not getting focus

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.6



      Name: diC59631 Date: 02/26/99


      The following code shows two JInternalFrames both with Buttons.
      Without giving focus to the internal frames, click a button.
      Notice that the button processes the event, but the frame containing
      the selected button is never selected. This occurs on Solaris 2.6 with
      JDK1.2.

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

      public class test
      extends
      JFrame
      {
      public static void main(String args[])
      {
      new test();
      }

      public test()
      {
      JDesktopPane desktop = new JDesktopPane();

      getContentPane().setLayout(new BorderLayout());
      getContentPane().add(desktop, BorderLayout.CENTER);
      desktop.setPreferredSize(new Dimension(300,300));
      desktop.add(frame1(), JLayeredPane.DEFAULT_LAYER);
      desktop.add(frame2(), JLayeredPane.DEFAULT_LAYER);
      pack();
      show();
      }

      JInternalFrame frame1()
      {
      JInternalFrame frame = new JInternalFrame("frame1");
      JPanel panel = new JPanel();
      JButton btn1 = new JButton("button 1");
      btn1.addActionListener(new ActionListener()
      {
      public void actionPerformed(ActionEvent evt)
      {
      System.out.println("button 1 pressed");
      }
      });

      panel.add(btn1);

      frame.getContentPane().add(panel);
      frame.setBounds(10,10, 120, 70);
      return frame;
      }

      JInternalFrame frame2()
      {
      JInternalFrame frame = new JInternalFrame("frame2");
      JPanel panel = new JPanel();
      JButton btn2 = new JButton("button 2");
      btn2.addActionListener(new ActionListener()
      {
      public void actionPerformed(ActionEvent evt)
      {
      System.out.println("button 2 pressed");
      }
      });

      panel.add(btn2);

      frame.getContentPane().add(panel);
      frame.setBounds(10,80, 120, 70);
      return frame;
      }
      }
      (Review ID: 54541)
      ======================================================================

            apikalev Andrey Pikalev
            dindrigo Daniel Indrigo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: