Some apps (including Sun's Java2D demo, see below) seem to do strange things with JTabbedPane: they only install one component in the first tab, leav#e all other tabs at null and change this one component on some event. This requires that the JTabbedPane impl doesn't try to change the component when a null component is seen.
This gets the Java2D demo (included in Sun's JDK under demo/jfc/Java2D - BSD+nuke license) running: http://kennke.org/~roman/Bildschirmfoto.png 2006-06-09 Roman Kennke <[EMAIL PROTECTED]> * javax/swing/JTabbedPane.java (setSelectedIndex): Don't change the visibility of the components, this is done by the UI class. * javax/swing/plaf/basic/BasicTabbedPaneUI.java (TabbedPaneLayout.layoutContainer): Change visibility of component here, depending on the selected index. Only do this if the new selected component is not null. Some programs seem to expect this. (visibleComponent): New field. (getVisibleComponent): Changed to return visibleComponent field. (setVisibleComponent): Changed to set the visibility of the old and new visible component. /Roman -- “Improvement makes straight roads, but the crooked roads, without Improvement, are roads of Genius.” - William Blake
Index: javax/swing/JTabbedPane.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTabbedPane.java,v
retrieving revision 1.40
diff -u -1 -0 -r1.40 JTabbedPane.java
--- javax/swing/JTabbedPane.java 31 May 2006 13:17:41 -0000 1.40
+++ javax/swing/JTabbedPane.java 9 Jun 2006 23:33:36 -0000
@@ -983,24 +983,20 @@
* This method sets the selected index. This method will hide the old
* component and show the new component.
*
* @param index The index to set it at.
*/
public void setSelectedIndex(int index)
{
checkIndex(index, -1, tabs.size());
if (index != getSelectedIndex())
{
- if (getSelectedIndex() != -1 && getSelectedComponent() != null)
- getSelectedComponent().hide();
- if (index != -1 && getComponentAt(index) != null)
- getComponentAt(index).show();
model.setSelectedIndex(index);
}
}
/**
* This method returns the component at the selected index.
*
* @return The component at the selected index.
*/
public Component getSelectedComponent()
Index: javax/swing/plaf/basic/BasicTabbedPaneUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTabbedPaneUI.java,v
retrieving revision 1.45
diff -u -1 -0 -r1.45 BasicTabbedPaneUI.java
--- javax/swing/plaf/basic/BasicTabbedPaneUI.java 7 Jun 2006 18:50:57 -0000 1.45
+++ javax/swing/plaf/basic/BasicTabbedPaneUI.java 9 Jun 2006 23:33:39 -0000
@@ -523,20 +523,31 @@
* of all its components.
*
* @param parent The Container to lay out.
*/
public void layoutContainer(Container parent)
{
calculateLayoutInfo();
int tabPlacement = tabPane.getTabPlacement();
Insets insets = tabPane.getInsets();
+
+ int selectedIndex = tabPane.getSelectedIndex();
+ Component selectedComponent = tabPane.getComponentAt(selectedIndex);
+ // The RI doesn't seem to change the component if the new selected
+ // component == null. This is probably so that applications can add
+ // one single component for every tab.
+ if (selectedComponent != null)
+ {
+ setVisibleComponent(selectedComponent);
+ }
+
int childCount = tabPane.getComponentCount();
if (childCount > 0)
{
int compX;
int compY;
int tabAreaWidth = 0;
int tabAreaHeight = 0;
switch (tabPlacement)
{
case LEFT:
@@ -1404,20 +1415,25 @@
*/
private int rolloverTab;
/**
* Determines if tabs are painted opaque or not. This can be adjusted using
* the UIManager property 'TabbedPane.tabsOpaque'.
*/
private boolean tabsOpaque;
/**
+ * The currently visible component.
+ */
+ private Component visibleComponent;
+
+ /**
* Creates a new BasicTabbedPaneUI object.
*/
public BasicTabbedPaneUI()
{
super();
rects = new Rectangle[0];
tabRuns = new int[10];
}
/**
@@ -2472,32 +2488,43 @@
return dest;
}
/**
* This method returns the component that is shown in the content area.
*
* @return The component that is shown in the content area.
*/
protected Component getVisibleComponent()
{
- return tabPane.getComponentAt(tabPane.getSelectedIndex());
+ return visibleComponent;
}
/**
* This method sets the visible component.
*
* @param component The component to be set visible.
*/
protected void setVisibleComponent(Component component)
{
- component.setVisible(true);
- tabPane.setSelectedComponent(component);
+ // Make old component invisible.
+ if (visibleComponent != null && visibleComponent != component
+ && visibleComponent.getParent() == tabPane)
+ {
+ visibleComponent.setVisible(false);
+ }
+
+ // Make new component visible.
+ if (component != null && ! component.isVisible())
+ {
+ component.setVisible(true);
+ }
+ visibleComponent = component;
}
/**
* This method assures that enough rectangles are created given the
* tabCount. The old array is copied to the new one.
*
* @param tabCount The number of tabs.
*/
protected void assureRectsCreated(int tabCount)
{
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
