-
Bug
-
Resolution: Fixed
-
P3
-
1.1, 1.2.0
-
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());
}
}
(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());
}
}
- duplicates
-
JDK-4193990 List of JTabbedPane problems for Swing1.1beta3
-
- Closed
-
- relates to
-
JDK-4196100 findComponentAt() not working properly with JTabbedPane
-
- Resolved
-