This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui][PATCH] JTabbedPane fixes.
- From: Kim Ho <kho at redhat dot com>
- To: java-patches <java-patches at gcc dot gnu dot org>
- Date: Tue, 15 Jun 2004 13:26:48 -0400
- Subject: [gui][PATCH] JTabbedPane fixes.
Hi,
This fixes a couple problems with JTabbedPane.
Cheers,
Kim
2004-06-15 Kim Ho <kho@redhat.com>
* javax/swing/JTabbedPane.java
(setComponent): Remove old component and
add new component.
(setSelectedIndex): Don't operate on the
components if they're null. Don't set index
on the model if the index is the same.
(insertTab): Don't add or hide the component
if it's null. Repaint the container.
* javax/swing/plaf/basic/BasicLookAndFeel.java
Change colors for TabbedPane.
* javax/swing/plaf/basic/BasicTabbedPaneUI.java
(mousePressed): Re-layout and paint the component.
(layoutContainer): Don't set location on the view.
(ScrollingViewport::paint): Remove.
? tabbedpane.patch
Index: javax/swing/JTabbedPane.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JTabbedPane.java,v
retrieving revision 1.3.2.5
diff -u -r1.3.2.5 JTabbedPane.java
--- javax/swing/JTabbedPane.java 14 Jun 2004 17:35:32 -0000 1.3.2.5
+++ javax/swing/JTabbedPane.java 15 Jun 2004 17:19:56 -0000
@@ -312,7 +312,9 @@
*/
public void setComponent(Component c)
{
+ JTabbedPane.this.remove(component);
this.component = c;
+ JTabbedPane.this.add(c);
}
/**
@@ -833,12 +835,12 @@
checkIndex(index, -1, tabs.size());
if (index != getSelectedIndex())
{
- if (getSelectedIndex() != -1)
+ if (getSelectedIndex() != -1 && getSelectedComponent() != null)
getSelectedComponent().hide();
- if (index != -1)
+ if (index != -1 && getComponentAt(index) != null)
getComponentAt(index).show();
+ model.setSelectedIndex(index);
}
- model.setSelectedIndex(index);
}
/**
@@ -882,13 +884,17 @@
// Hide the component so we don't see it. Do it before we parent it
// so we don't trigger a repaint.
- component.hide();
- super.add(component);
-
+ if (component != null)
+ {
+ component.hide();
+ super.add(component);
+ }
+
if (getSelectedIndex() == -1)
setSelectedIndex(0);
layout();
+ repaint();
}
/**
Index: javax/swing/plaf/basic/BasicLookAndFeel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicLookAndFeel.java,v
retrieving revision 1.4.2.11
diff -u -r1.4.2.11 BasicLookAndFeel.java
--- javax/swing/plaf/basic/BasicLookAndFeel.java 9 Jun 2004 20:55:11 -0000 1.4.2.11
+++ javax/swing/plaf/basic/BasicLookAndFeel.java 15 Jun 2004 17:19:57 -0000
@@ -704,7 +704,7 @@
"ctrl UP", "requestFocus",
"ctrl KP_UP", "requestFocus"
}),
- "TabbedPane.background", new ColorUIResource(Color.GRAY),
+ "TabbedPane.background", new ColorUIResource(Color.LIGHT_GRAY),
"TabbedPane.contentBorderInsets", new InsetsUIResource(2, 2, 3, 3),
"TabbedPane.darkShadow", new ColorUIResource(Color.darkGray),
"TabbedPane.focus", new ColorUIResource(Color.black),
Index: javax/swing/plaf/basic/BasicTabbedPaneUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/BasicTabbedPaneUI.java,v
retrieving revision 1.3.16.6
diff -u -r1.3.16.6 BasicTabbedPaneUI.java
--- javax/swing/plaf/basic/BasicTabbedPaneUI.java 9 Jun 2004 08:40:09 -0000 1.3.16.6
+++ javax/swing/plaf/basic/BasicTabbedPaneUI.java 15 Jun 2004 17:19:57 -0000
@@ -160,6 +160,8 @@
// e.g. in the inset area.
if (index != -1 && tabPane.isEnabledAt(index))
tabPane.setSelectedIndex(index);
+ tabPane.layout();
+ tabPane.repaint();
}
}
@@ -1085,7 +1087,7 @@
// we want to cover that entire space so that borders that run under
// the tab area don't show up when we move the viewport around.
- panel.setBounds(0, 0, w + p.x, h + p.y);
+ panel.setSize(w + p.x, h + p.y);
}
viewport.setViewPosition(findPointForIndex(currentScrollLocation));
}
@@ -1154,31 +1156,6 @@
*/
private class ScrollingViewport extends JViewport implements UIResource
{
- /**
- * This method is temporary until the viewport layouts are implemented.
- * Need it because the flow layout it currently moves our panel around.
- *
- * @param g The graphics object to paint with.
- */
- public void paint(Graphics g)
- {
- // FIXME: Remove this as well.
- int tabC = tabPane.getTabCount() - 1;
- if (tabC + 1 > 0)
- {
- int w = Math.max(rects[tabC].width + rects[tabC].x, tabAreaRect.width);
- int h = Math.max(rects[tabC].height, tabAreaRect.height);
- Point p = findPointForIndex(currentScrollLocation);
-
- // we want to cover that entire space so that borders that run under
- // the tab area don't show up when we move the viewport around.
- panel.setBounds(0, 0, w + p.x, h + p.y);
- }
-
- // FIXME: Remove when ViewportLayout is done.
- setViewPosition(findPointForIndex(currentScrollLocation));
- super.paint(g);
- }
}
/**
@@ -1997,7 +1974,7 @@
int x, int y, int w, int h, boolean isSelected)
{
Color saved = g.getColor();
-
+
if (! isSelected || tabPlacement != SwingConstants.TOP)
{
g.setColor(shadow);