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

findComponentAt() not working properly with JTabbedPane

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.3.0
    • 1.1, 1.2.0
    • client-libs
    • kestrel
    • generic
    • generic, solaris_10

      The following bug shows that findComponentAt() is not returning the
      correct component for JTabbedPane.


      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;

      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));
                      test.addWindowListener(
                                      new WindowAdapter() {
                                      public void windowClosing(WindowEvent e) {System.exit(0);}
                                      }
                              );

                      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());
              }
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: