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

SwingUtilities.getDeepestComponentAt() not working for JTabbedPane

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.2
    • 1.1, 1.2.0
    • client-libs
    • None
    • 1.2.2
    • generic
    • solaris_2.6, solaris_10

      The program below illustrates a bug with SwingUtilities.getDeepestComponentAt():
      (this method is provided as an alternative to Container.findComponentAt)

      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import java.awt.Color;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;
      import javax.swing.JFrame;
      import javax.swing.JTabbedPane;
      import javax.swing.JPanel;
      import javax.swing.SwingUtilities;

      public class FolderTest extends JFrame {

              public FolderTest() {
                      super("Folder Test");
              }

              public static void main(String args[]) {
                      FolderTest test = new FolderTest();
                      test.setSize(new Dimension(200, 200));

                      JTabbedPane tabbedpane = new JTabbedPane();
                      test.setContentPane(tabbedpane);

                      JPanel panel1 = new JPanel();
                      panel1.setName("Panel 1");
                      panel1.setLayout(new BorderLayout());
                      tabbedpane.add(panel1);
                      JPanel subPanel = new JPanel();
                      subPanel.setName("Sub-Panel");
                      subPanel.setBackground(Color.green);
                      panel1.add(subPanel); // add sub panel to 1st tab

                      JPanel panel2 = new JPanel();
                      panel2.setName("Panel 2");
                      tabbedpane.add(panel2);

                      tabbedpane.setSelectedIndex(1); // display 2nd tab
                      test.setVisible(true);

                      // incorrectly finds sub panel (currently hidden in panel 1)...should return
                      // panel 2
                      //System.out.println(tabbedpane.findComponentAt(50,50).getName());
                      System.out.println(SwingUtilities.getDeepestComponentAt(tabbedpane, 50, 50).getName());
              }
      }

            amfowler Anne Fowler (Inactive)
            amfowler Anne Fowler (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: