-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.2.0
-
None
-
generic
-
solaris_2.6
There seems to be 6 potential problems with the JTabbedPane in
Swing 1.1beta3 compared to Swing 1.0.1. The test case that follows
the list of problems covers the first 3 problems.
Here is the list of potential problems:
1) Each of the components in the tabbed pane are called
with setVisible to false when the tab is added even
though they may be already invisible. This generates
an unnecessary componentHidden event.
2) A setVisible(true) is called on a component in a
nested tabbed pane even though it and the tab are not visible
to the user. The component may flash visible briefly before
the current tab paints over it. See example for more details.
3) There is an inconsistency between the inner tabbed pane
and the outer tabbed pane. When first shown, he outer one will
have the current tab component called with a componentShown.
When the nestedTabbedPane is shown, the current tab component
is never called with a componentShown.
4) When the JFrame is setVisible, the componentShown of the tab
component is called before the componentShown of the JFrame.
5) Sometimes, the toolbar above the JTabbedPane is painted again
in odd locations when the current tab is changes.
6) SwingUtilities.getDeepestComponentAt() does not work correctly
with JTabbedPane. It checks for visibility of the component
after the recursive return. Thus, it can return a visible
component that is inside an invisible one such as in a tabbed
pane. It needs to check for visibility before doing the
recursive call.
Some of problems can be worked around by unhooking the componentListeners
of the component when added to the tabbedPane and re-hooking them up
when removed from the tabbedPane. Also, the getDeepestComponentAt()
method can be copied and modified. Even though we can work around some
of the problems, JavaSoft should fix the component event model.
Here is the example of the first three problems:
/*
* JTabbedPaneProblem.java
*
* This is a test application for showing problems with
* JTabbedPanes in Swing 1.1beta3. The component events
* (setVisible calls) are occurring at the wrong time - when
* people do not expect them.
*
* This example is simplified
* to show the problems. The serious problems occur when
* we have reusable components that have component listeners
* and they are added as tabs.
*
* Problems:
*
* 1) Each of the components in the tabbed pane are called
* with setVisible to false when the tab is added.
* This generates a componentHidden event. Since the
* components are already invisible (or hidden), this
* event is redundant. We can filter it out by using
* a firstShown boolean flag.
*
* 2) A setVisible(true) is called on a component in a
* nested tabbed pane even though it is not visible
* to the user. This is serious. With other examples,
* component in the nest tabbed pane is briefly visible before
* before the outer tabbed pane paints over it.
* I don't think that BasicTabbedPaneUI should be trying
* to calculate the layout of an invisible component.
* Instead it should be done when it is shown.
*
* 3) There is an inconsistency between the inner tabbed pane
* and the outer tabbed pane. The outer one will have
* the current tab component called with a componentShown
* when it is made visible to the user. The inner one
* will not call its current tab component with a componentShown
* when it is made visible by a mouse click on its tab.
*
* To Run:
*
* java JTabbedPaneProblem
*
* Output:
* comp1 - componentHidden <--- Problem 1
* comp2 - componentHidden <--- Problem 1
* comp3 - componentHidden <--- Problem 1
* comp4 - componentHidden <--- Problem 1
* comp1 - componentShown
* comp3 - componentShown <--- Problem 2
*
* I think that it only should be "comp1 - componentShown".
* The "comp3 - componentShown" is unacceptable.
*
* Now, mouse click on the "Nested" tab. Output will be:
*
* comp1 - componentHidden
*
* There should have also been a "comp3 - componentShown"
* here (Problem 3).
*
*
*/
import javax.swing.*;
import java.awt.event.*;
public class JTabbedPaneProblem extends JFrame {
public JTabbedPaneProblem( ) {
JTabbedPane tabbedPane = new JTabbedPane();
// the first tab
MyTabComponent comp1 = new MyTabComponent("comp1");
tabbedPane.addTab("First", comp1);
// the second tab is a JTextArea
MyTabComponent comp2 = new MyTabComponent("comp2");
tabbedPane.addTab("Second", comp2);
// the third tab is nested tabbed pane with
// components comp3 and comp4
JTabbedPane nestedTabbedPane = new JTabbedPane();
MyTabComponent comp3 = new MyTabComponent("comp3");
nestedTabbedPane.addTab("Third", comp3);
MyTabComponent comp4 = new MyTabComponent("comp4");
nestedTabbedPane.addTab("Fourth", comp4);
tabbedPane.addTab("Nested", nestedTabbedPane);
getContentPane().add( tabbedPane );
setSize(600,400);
}
public static void main( String args[] ) {
JTabbedPaneProblem testApp = new JTabbedPaneProblem();
testApp.setVisible( true );
}
}
class MyTabComponent extends JPanel {
String name;
public MyTabComponent( String name ) {
this.name = name;
addComponentListener( new ComponentAdapter() {
public void componentShown( ComponentEvent evt ) {
System.out.println(
MyTabComponent.this.name+" - componentShown");
}
public void componentHidden( ComponentEvent evt ) {
System.out.println(
MyTabComponent.this.name+" - componentHidden");
}
} );
}
}
nasser.nouri@Corp 1998-12-01
Swing 1.1beta3 compared to Swing 1.0.1. The test case that follows
the list of problems covers the first 3 problems.
Here is the list of potential problems:
1) Each of the components in the tabbed pane are called
with setVisible to false when the tab is added even
though they may be already invisible. This generates
an unnecessary componentHidden event.
2) A setVisible(true) is called on a component in a
nested tabbed pane even though it and the tab are not visible
to the user. The component may flash visible briefly before
the current tab paints over it. See example for more details.
3) There is an inconsistency between the inner tabbed pane
and the outer tabbed pane. When first shown, he outer one will
have the current tab component called with a componentShown.
When the nestedTabbedPane is shown, the current tab component
is never called with a componentShown.
4) When the JFrame is setVisible, the componentShown of the tab
component is called before the componentShown of the JFrame.
5) Sometimes, the toolbar above the JTabbedPane is painted again
in odd locations when the current tab is changes.
6) SwingUtilities.getDeepestComponentAt() does not work correctly
with JTabbedPane. It checks for visibility of the component
after the recursive return. Thus, it can return a visible
component that is inside an invisible one such as in a tabbed
pane. It needs to check for visibility before doing the
recursive call.
Some of problems can be worked around by unhooking the componentListeners
of the component when added to the tabbedPane and re-hooking them up
when removed from the tabbedPane. Also, the getDeepestComponentAt()
method can be copied and modified. Even though we can work around some
of the problems, JavaSoft should fix the component event model.
Here is the example of the first three problems:
/*
* JTabbedPaneProblem.java
*
* This is a test application for showing problems with
* JTabbedPanes in Swing 1.1beta3. The component events
* (setVisible calls) are occurring at the wrong time - when
* people do not expect them.
*
* This example is simplified
* to show the problems. The serious problems occur when
* we have reusable components that have component listeners
* and they are added as tabs.
*
* Problems:
*
* 1) Each of the components in the tabbed pane are called
* with setVisible to false when the tab is added.
* This generates a componentHidden event. Since the
* components are already invisible (or hidden), this
* event is redundant. We can filter it out by using
* a firstShown boolean flag.
*
* 2) A setVisible(true) is called on a component in a
* nested tabbed pane even though it is not visible
* to the user. This is serious. With other examples,
* component in the nest tabbed pane is briefly visible before
* before the outer tabbed pane paints over it.
* I don't think that BasicTabbedPaneUI should be trying
* to calculate the layout of an invisible component.
* Instead it should be done when it is shown.
*
* 3) There is an inconsistency between the inner tabbed pane
* and the outer tabbed pane. The outer one will have
* the current tab component called with a componentShown
* when it is made visible to the user. The inner one
* will not call its current tab component with a componentShown
* when it is made visible by a mouse click on its tab.
*
* To Run:
*
* java JTabbedPaneProblem
*
* Output:
* comp1 - componentHidden <--- Problem 1
* comp2 - componentHidden <--- Problem 1
* comp3 - componentHidden <--- Problem 1
* comp4 - componentHidden <--- Problem 1
* comp1 - componentShown
* comp3 - componentShown <--- Problem 2
*
* I think that it only should be "comp1 - componentShown".
* The "comp3 - componentShown" is unacceptable.
*
* Now, mouse click on the "Nested" tab. Output will be:
*
* comp1 - componentHidden
*
* There should have also been a "comp3 - componentShown"
* here (Problem 3).
*
*
*/
import javax.swing.*;
import java.awt.event.*;
public class JTabbedPaneProblem extends JFrame {
public JTabbedPaneProblem( ) {
JTabbedPane tabbedPane = new JTabbedPane();
// the first tab
MyTabComponent comp1 = new MyTabComponent("comp1");
tabbedPane.addTab("First", comp1);
// the second tab is a JTextArea
MyTabComponent comp2 = new MyTabComponent("comp2");
tabbedPane.addTab("Second", comp2);
// the third tab is nested tabbed pane with
// components comp3 and comp4
JTabbedPane nestedTabbedPane = new JTabbedPane();
MyTabComponent comp3 = new MyTabComponent("comp3");
nestedTabbedPane.addTab("Third", comp3);
MyTabComponent comp4 = new MyTabComponent("comp4");
nestedTabbedPane.addTab("Fourth", comp4);
tabbedPane.addTab("Nested", nestedTabbedPane);
getContentPane().add( tabbedPane );
setSize(600,400);
}
public static void main( String args[] ) {
JTabbedPaneProblem testApp = new JTabbedPaneProblem();
testApp.setVisible( true );
}
}
class MyTabComponent extends JPanel {
String name;
public MyTabComponent( String name ) {
this.name = name;
addComponentListener( new ComponentAdapter() {
public void componentShown( ComponentEvent evt ) {
System.out.println(
MyTabComponent.this.name+" - componentShown");
}
public void componentHidden( ComponentEvent evt ) {
System.out.println(
MyTabComponent.this.name+" - componentHidden");
}
} );
}
}
nasser.nouri@Corp 1998-12-01
- duplicates
-
JDK-4212109 SwingUtilities.getDeepestComponentAt() not working for JTabbedPane
-
- Resolved
-