2 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import java
.awt
.Color
;
42 import java
.awt
.Component
;
43 import java
.awt
.Point
;
44 import java
.awt
.Rectangle
;
45 import java
.awt
.event
.MouseEvent
;
46 import java
.io
.Serializable
;
47 import java
.util
.Vector
;
49 import javax
.accessibility
.Accessible
;
50 import javax
.accessibility
.AccessibleContext
;
51 import javax
.accessibility
.AccessibleRole
;
52 import javax
.accessibility
.AccessibleSelection
;
53 import javax
.swing
.event
.ChangeEvent
;
54 import javax
.swing
.event
.ChangeListener
;
55 import javax
.swing
.plaf
.TabbedPaneUI
;
56 import javax
.swing
.plaf
.UIResource
;
59 * This is a container for components. One component is displayed at a time.
60 * Users can switch between components by clicking on tabs.
63 * Tabs can be oriented in several ways. They can be above, below, left and
64 * right of the component. Tabs can either wrap around (by creating multiple
65 * rows of tabs) or they can be scrolled (where only a subset of the tabs
66 * can be seen at once). More tabs can be added by calling the
67 * add/addTab/insertTab methods.
70 public class JTabbedPane
extends JComponent
implements Serializable
,
77 protected class AccessibleJTabbedPane
extends JComponent
.AccessibleJComponent
78 implements AccessibleSelection
, ChangeListener
81 private static final long serialVersionUID
= 7610530885966830483L;
84 * Creates a new AccessibleJTabbedPane object.
86 public AccessibleJTabbedPane()
94 * @param e DOCUMENT ME!
96 public void stateChanged(ChangeEvent e
)
103 * @return DOCUMENT ME!
105 public AccessibleRole
getAccessibleRole()
113 * @return DOCUMENT ME!
115 public int getAccessibleChildrenCount()
123 * @param i DOCUMENT ME!
125 * @return DOCUMENT ME!
127 public Accessible
getAccessibleChild(int i
)
135 * @return DOCUMENT ME!
137 public AccessibleSelection
getAccessibleSelection()
145 * @param p DOCUMENT ME!
147 * @return DOCUMENT ME!
149 public Accessible
getAccessibleAt(Point p
)
157 * @return DOCUMENT ME!
159 public int getAccessibleSelectionCount()
167 * @param i DOCUMENT ME!
169 * @return DOCUMENT ME!
171 public Accessible
getAccessibleSelection(int i
)
179 * @param i DOCUMENT ME!
181 * @return DOCUMENT ME!
183 public boolean isAccessibleChildSelected(int i
)
191 * @param i DOCUMENT ME!
193 public void addAccessibleSelection(int i
)
200 * @param i DOCUMENT ME!
202 public void removeAccessibleSelection(int i
)
209 public void clearAccessibleSelection()
216 public void selectAllAccessibleSelection()
222 * A helper class that listens for changes to the model.
224 protected class ModelListener
implements ChangeListener
, Serializable
227 private static final long serialVersionUID
= 497359819958114132L;
230 * Creates a new ModelListener object.
232 protected ModelListener()
237 * This method is called whenever the model is changed.
239 * @param e The ChangeEvent that is passed from the model.
241 public void stateChanged(ChangeEvent e
)
243 // Propagate to our listeners.
249 * A private class that holds all the information for each tab.
253 /** The tooltip string. */
256 /** The component associated with the tab. */
257 private Component component
;
259 /** The active icon associated with the tab. */
260 private transient Icon icon
;
262 /** The disabled icon associated with the tab. */
263 private transient Icon disabledIcon
;
265 /** The tab's enabled status. */
266 private transient boolean enabled
= true;
268 /** The string painted on the tab. */
269 private transient String title
;
271 /** The background color of the tab. */
272 private transient Color bg
;
274 /** The foreground color of the tab. */
275 private transient Color fg
;
277 /** The mnemonic associated with the tab. */
278 private transient int mnemonicKey
;
280 /** The index of the underlined character in the string. */
281 private transient int underlinedChar
= -1;
284 * Creates a new data storage for the tab.
286 * @param title The string displayed on the tab.
287 * @param icon The active icon displayed on the tab.
288 * @param component The component associated with the tab.
289 * @param tip The tooltip associated with the tab.
291 protected Page(String title
, Icon icon
, Component component
, String tip
)
295 this.component
= component
;
300 * This method returns the component associated with the tab.
302 * @return The component associated with the tab.
304 public Component
getComponent()
310 * This method sets the component associated with the tab.
312 * @param c The component associated with the tab.
314 public void setComponent(Component c
)
322 * This method returns the tooltip string.
324 * @return The tooltip string.
326 public String
getTip()
332 * This method sets the tooltip string.
334 * @param tip The tooltip string.
336 public void setTip(String tip
)
342 * This method returns the background color.
344 * @return The background color.
346 public Color
getBackground()
352 * This method sets the background color.
354 * @param background The background color.
356 public void setBackground(Color background
)
362 * This method returns the foreground color.
364 * @return The foreground color.
366 public Color
getForeground()
372 * This method sets the foreground color.
374 * @param foreground The foreground color.
376 public void setForeground(Color foreground
)
382 * This method returns the title associated with the tab.
384 * @return The title of the tab.
386 public String
getTitle()
392 private static final long serialVersionUID
= 1614381073220130939L;
395 * This method sets the title of the tab.
397 * @param text The title of the tab.
399 public void setTitle(String text
)
402 if (title
!= null && title
.length() <= underlinedChar
)
403 setDisplayedMnemonicIndex(title
.length() - 1);
407 * This method returns the active icon.
409 * @return The active icon.
411 public Icon
getIcon()
417 * This method sets the active icon.
419 * @param icon The active icon.
421 public void setIcon(Icon icon
)
427 * This method returns the disabled icon.
429 * @return The disabled icon.
431 public Icon
getDisabledIcon()
433 if (disabledIcon
== null && icon
instanceof ImageIcon
)
434 setDisabledIcon(icon
);
439 * This method sets the disabled icon.
441 * @param disabledIcon The disabled icon.
443 public void setDisabledIcon(Icon disabledIcon
)
445 this.disabledIcon
= disabledIcon
;
449 * This method returns whether the tab is enabled.
451 * @return Whether the tab is enabled.
453 public boolean isEnabled()
459 * This method sets whether the tab is enabled.
461 * @param enabled Whether this tab is enabled.
463 public void setEnabled(boolean enabled
)
465 this.enabled
= enabled
;
469 * This method returns the mnemonic.
471 * @return The mnemonic.
473 public int getMnemonic()
475 return (int) mnemonicKey
;
479 * This method sets the mnemonic. If the title is set, it will update the
482 * @param key The mnemonic.
484 public void setMnemonic(int key
)
486 setMnemonic((char) key
);
490 * This method sets the mnemonic. If the title is set, it will update the
493 * @param aChar The mnemonic.
495 public void setMnemonic(char aChar
)
499 setDisplayedMnemonicIndex(title
.indexOf(mnemonicKey
));
503 * This method returns the mnemonicIndex.
505 * @return The mnemonicIndex.
507 public int getDisplayedMnemonicIndex()
509 return underlinedChar
;
513 * This method sets the mnemonicIndex.
515 * @param index The mnemonicIndex.
517 * @throws IllegalArgumentException If index less than -1 || index greater
518 * or equal to title.length.
520 public void setDisplayedMnemonicIndex(int index
)
521 throws IllegalArgumentException
523 if (index
< -1 || title
!= null && index
>= title
.length())
524 throw new IllegalArgumentException();
526 if (title
== null || mnemonicKey
== 0 || title
.charAt(index
) != mnemonicKey
)
529 underlinedChar
= index
;
533 /** The changeEvent used to fire changes to listeners. */
534 protected ChangeEvent changeEvent
;
536 /** The listener that listens to the model. */
537 protected ChangeListener changeListener
;
539 /** The model that describes this JTabbedPane. */
540 protected SingleSelectionModel model
;
542 /** Indicates that the TabbedPane is in scrolling mode. */
543 public static final int SCROLL_TAB_LAYOUT
= 1;
545 /** Indicates that the TabbedPane is in wrap mode. */
546 public static final int WRAP_TAB_LAYOUT
= 0;
548 /** The current tabPlacement of the TabbedPane. */
549 protected int tabPlacement
= SwingConstants
.TOP
;
551 /** The current tabLayoutPolicy of the TabbedPane. */
552 private transient int layoutPolicy
;
554 /** The list of tabs associated with the TabbedPane. */
555 transient Vector tabs
= new Vector();
558 * Creates a new JTabbedPane object with tabs on top and using wrap tab
563 this(SwingConstants
.TOP
, WRAP_TAB_LAYOUT
);
567 * Creates a new JTabbedPane object using wrap tab layout and the given
570 * @param tabPlacement Where the tabs will be placed.
572 public JTabbedPane(int tabPlacement
)
574 this(tabPlacement
, WRAP_TAB_LAYOUT
);
578 * Creates a new JTabbedPane object with the given tabPlacement and
581 * @param tabPlacement Where the tabs will be placed.
582 * @param tabLayoutPolicy The way tabs will be placed.
584 * @throws IllegalArgumentException If tabLayoutPolicy or tabPlacement are
587 public JTabbedPane(int tabPlacement
, int tabLayoutPolicy
)
589 if (tabPlacement
!= TOP
&& tabPlacement
!= BOTTOM
&& tabPlacement
!= RIGHT
590 && tabPlacement
!= LEFT
)
591 throw new IllegalArgumentException("tabPlacement is not valid.");
592 if (tabLayoutPolicy
!= SCROLL_TAB_LAYOUT
593 && tabLayoutPolicy
!= WRAP_TAB_LAYOUT
)
594 throw new IllegalArgumentException("tabLayoutPolicy is not valid.");
595 this.tabPlacement
= tabPlacement
;
596 layoutPolicy
= tabLayoutPolicy
;
598 changeEvent
= new ChangeEvent(this);
599 changeListener
= createChangeListener();
601 model
= new DefaultSingleSelectionModel();
602 model
.addChangeListener(changeListener
);
608 * This method returns the UI used to display the JTabbedPane.
610 * @return The UI used to display the JTabbedPane.
612 public TabbedPaneUI
getUI()
614 return (TabbedPaneUI
) ui
;
618 * This method sets the UI used to display the JTabbedPane.
620 * @param ui The UI used to display the JTabbedPane.
622 public void setUI(TabbedPaneUI ui
)
628 * This method restores the UI to the defaults given by the UIManager.
630 public void updateUI()
632 setUI((TabbedPaneUI
) UIManager
.getUI(this));
637 * This method returns a string identifier that is used to determine which
638 * UI will be used with the JTabbedPane.
640 * @return A string identifier for the UI.
642 public String
getUIClassID()
644 return "TabbedPaneUI";
648 * This method creates a ChangeListener that is used to listen to the model
651 * @return A ChangeListener to listen to the model.
653 protected ChangeListener
createChangeListener()
655 return new ModelListener();
659 * This method adds a ChangeListener to the JTabbedPane.
661 * @param l The ChangeListener to add.
663 public void addChangeListener(ChangeListener l
)
665 listenerList
.add(ChangeListener
.class, l
);
669 * This method removes a ChangeListener to the JTabbedPane.
671 * @param l The ChangeListener to remove.
673 public void removeChangeListener(ChangeListener l
)
675 listenerList
.remove(ChangeListener
.class, l
);
679 * This method fires a ChangeEvent to all the JTabbedPane's ChangeListeners.
681 protected void fireStateChanged()
683 Object
[] changeListeners
= listenerList
.getListenerList();
684 if (changeEvent
== null)
685 changeEvent
= new ChangeEvent(this);
686 for (int i
= changeListeners
.length
- 2; i
>= 0; i
-= 2)
688 if (changeListeners
[i
] == ChangeListener
.class)
689 ((ChangeListener
) changeListeners
[i
+ 1]).stateChanged(changeEvent
);
694 * This method returns all ChangeListeners registered with the JTabbedPane.
696 * @return The ChangeListeners registered with the JTabbedPane.
698 public ChangeListener
[] getChangeListeners()
700 return (ChangeListener
[]) super.getListeners(ChangeListener
.class);
704 * This method returns the model used with the JTabbedPane.
706 * @return The JTabbedPane's model.
708 public SingleSelectionModel
getModel()
714 * This method changes the model property of the JTabbedPane.
716 * @param model The new model to use with the JTabbedPane.
718 public void setModel(SingleSelectionModel model
)
720 if (model
!= this.model
)
722 SingleSelectionModel oldModel
= this.model
;
723 this.model
.removeChangeListener(changeListener
);
725 this.model
.addChangeListener(changeListener
);
726 firePropertyChange("model", oldModel
, this.model
);
731 * This method returns the tabPlacement.
733 * @return The tabPlacement used with the JTabbedPane.
735 public int getTabPlacement()
741 * This method changes the tabPlacement property of the JTabbedPane.
743 * @param tabPlacement The tabPlacement to use.
745 * @throws IllegalArgumentException If tabPlacement is not one of TOP,
746 * BOTTOM, LEFT, or RIGHT.
748 public void setTabPlacement(int tabPlacement
)
750 if (tabPlacement
!= TOP
&& tabPlacement
!= BOTTOM
&& tabPlacement
!= RIGHT
751 && tabPlacement
!= LEFT
)
752 throw new IllegalArgumentException("tabPlacement is not valid.");
753 if (tabPlacement
!= this.tabPlacement
)
755 int oldPlacement
= this.tabPlacement
;
756 this.tabPlacement
= tabPlacement
;
757 firePropertyChange("tabPlacement", oldPlacement
, this.tabPlacement
);
762 * This method returns the tabLayoutPolicy.
764 * @return The tabLayoutPolicy.
766 public int getTabLayoutPolicy()
772 * This method changes the tabLayoutPolicy property of the JTabbedPane.
774 * @param tabLayoutPolicy The tabLayoutPolicy to use.
776 * @throws IllegalArgumentException If tabLayoutPolicy is not one of
777 * SCROLL_TAB_LAYOUT or WRAP_TAB_LAYOUT.
779 public void setTabLayoutPolicy(int tabLayoutPolicy
)
781 if (tabLayoutPolicy
!= SCROLL_TAB_LAYOUT
782 && tabLayoutPolicy
!= WRAP_TAB_LAYOUT
)
783 throw new IllegalArgumentException("tabLayoutPolicy is not valid.");
784 if (tabLayoutPolicy
!= layoutPolicy
)
786 int oldPolicy
= layoutPolicy
;
787 layoutPolicy
= tabLayoutPolicy
;
788 firePropertyChange("tabLayoutPolicy", oldPolicy
, layoutPolicy
);
793 * This method returns the index of the tab that is currently selected.
795 * @return The index of the selected tab.
797 public int getSelectedIndex()
799 return model
.getSelectedIndex();
803 * This method checks the index.
805 * @param index The index to check.
806 * @param start DOCUMENT ME!
807 * @param end DOCUMENT ME!
809 * @throws IndexOutOfBoundsException DOCUMENT ME!
811 private void checkIndex(int index
, int start
, int end
)
813 if (index
< start
|| index
>= end
)
814 throw new IndexOutOfBoundsException("Index < " + start
+ " || Index >= "
819 * This method sets the selected index. This method will hide the old
820 * component and show the new component.
822 * @param index The index to set it at.
824 public void setSelectedIndex(int index
)
826 checkIndex(index
, -1, tabs
.size());
827 if (index
!= getSelectedIndex())
829 if (getSelectedIndex() != -1 && getSelectedComponent() != null)
830 getSelectedComponent().hide();
831 if (index
!= -1 && getComponentAt(index
) != null)
832 getComponentAt(index
).show();
833 model
.setSelectedIndex(index
);
838 * This method returns the component at the selected index.
840 * @return The component at the selected index.
842 public Component
getSelectedComponent()
844 return getComponentAt(getSelectedIndex());
848 * This method sets the component at the selected index.
850 * @param c The component associated with the selected index.
852 public void setSelectedComponent(Component c
)
854 if (c
.getParent() == this)
855 setSelectedIndex(indexOfComponent(c
));
857 setComponentAt(getSelectedIndex(), c
);
861 * This method inserts tabs into JTabbedPane. This includes adding the
862 * component to the JTabbedPane and hiding it.
864 * @param title The title of the tab.
865 * @param icon The tab's icon.
866 * @param component The component associated with the tab.
867 * @param tip The tooltip for the tab.
868 * @param index The index to insert the tab at.
870 public void insertTab(String title
, Icon icon
, Component component
,
871 String tip
, int index
)
873 Page p
= new Page(title
, icon
, component
, tip
);
874 tabs
.insertElementAt(p
, index
);
876 // Hide the component so we don't see it. Do it before we parent it
877 // so we don't trigger a repaint.
878 if (component
!= null)
881 super.add(component
);
884 if (getSelectedIndex() == -1)
892 * This method adds a tab to the JTabbedPane.
894 * @param title The title of the tab.
895 * @param icon The icon for the tab.
896 * @param component The associated component.
897 * @param tip The associated tooltip.
899 public void addTab(String title
, Icon icon
, Component component
, String tip
)
901 insertTab(title
, icon
, component
, tip
, tabs
.size());
905 * This method adds a tab to the JTabbedPane.
907 * @param title The title of the tab.
908 * @param icon The icon for the tab.
909 * @param component The associated component.
911 public void addTab(String title
, Icon icon
, Component component
)
913 insertTab(title
, icon
, component
, null, tabs
.size());
917 * This method adds a tab to the JTabbedPane.
919 * @param title The title of the tab.
920 * @param component The associated component.
922 public void addTab(String title
, Component component
)
924 insertTab(title
, null, component
, null, tabs
.size());
928 * This method adds a tab to the JTabbedPane. The title of the tab is the
929 * Component's name. If the Component is an instance of UIResource, it
930 * doesn't add the tab and instead add the component directly to the
933 * @param component The associated component.
935 * @return The Component that was added.
937 public Component
add(Component component
)
939 if (component
instanceof UIResource
)
940 super.add(component
);
942 insertTab(component
.getName(), null, component
, null, tabs
.size());
947 * This method adds a tab to the JTabbedPane. If the Component is an
948 * instance of UIResource, it doesn't add the tab and instead add the
949 * component directly to the JTabbedPane.
951 * @param title The title of the tab.
952 * @param component The associated component.
954 * @return The Component that was added.
956 public Component
add(String title
, Component component
)
958 if (component
instanceof UIResource
)
959 super.add(component
);
961 insertTab(title
, null, component
, null, tabs
.size());
966 * This method adds a tab to the JTabbedPane. If the Component is an
967 * instance of UIResource, it doesn't add the tab and instead add the
968 * component directly to the JTabbedPane.
970 * @param component The associated component.
971 * @param index The index to insert the tab at.
973 * @return The Component that was added.
975 public Component
add(Component component
, int index
)
977 if (component
instanceof UIResource
)
978 super.add(component
);
980 insertTab(component
.getName(), null, component
, null, index
);
985 * This method adds a tab to the JTabbedPane. If the Component is an
986 * instance of UIResource, it doesn't add the tab and instead add the
987 * component directly to the JTabbedPane. If the constraints object is an
988 * icon, it will be used as the tab's icon. If the constraints object is a
989 * string, we will use it as the title.
991 * @param component The associated component.
992 * @param constraints The constraints object.
994 public void add(Component component
, Object constraints
)
996 add(component
, constraints
, tabs
.size());
1000 * This method adds a tab to the JTabbedPane. If the Component is an
1001 * instance of UIResource, it doesn't add the tab and instead add the
1002 * component directly to the JTabbedPane. If the constraints object is an
1003 * icon, it will be used as the tab's icon. If the constraints object is a
1004 * string, we will use it as the title.
1006 * @param component The associated component.
1007 * @param constraints The constraints object.
1008 * @param index The index to insert the tab at.
1010 public void add(Component component
, Object constraints
, int index
)
1012 if (component
instanceof UIResource
)
1013 super.add(component
);
1016 if (constraints
instanceof String
)
1017 insertTab((String
) constraints
, null, component
, null, index
);
1019 insertTab(component
.getName(),
1020 (constraints
instanceof Icon
) ?
(Icon
) constraints
: null,
1021 component
, null, index
);
1026 * The tab and it's associated component are removed. After the component
1027 * has been removed from the JTabbedPane, it's set visible to ensure that
1030 * @param index The index of the tab to remove.
1032 public void removeTabAt(int index
)
1034 checkIndex(index
, 0, tabs
.size());
1035 Component c
= getComponentAt(index
);
1036 super.remove(index
);
1042 * This method removes the component from the JTabbedPane. After the
1043 * component has been removed from the JTabbedPane, it's set visible to
1044 * ensure that it can be seen.
1046 * @param component The Component to remove.
1048 public void remove(Component component
)
1050 // This simply removes the component.
1051 int index
= indexOfComponent(component
);
1052 super.remove(component
);
1054 setComponentAt(index
, null);
1058 * This method removes the tab and component from the JTabbedPane. It simply
1059 * calls removeTabAt(int index).
1061 * @param index The index of the tab to remove.
1063 public void remove(int index
)
1069 * This method removes all tabs and associated components from the
1072 public void removeAll()
1074 for (int i
= tabs
.size() - 1; i
>= 0; i
--)
1079 * This method returns how many tabs are in the JTabbedPane.
1081 * @return The number of tabs in the JTabbedPane.
1083 public int getTabCount()
1089 * This method returns the number of runs used to paint the JTabbedPane.
1091 * @return The number of runs.
1093 public int getTabRunCount()
1095 return ((TabbedPaneUI
) ui
).getTabRunCount(this);
1099 * This method returns the tab title given the index.
1101 * @param index The index of the tab.
1103 * @return The title for the tab.
1105 public String
getTitleAt(int index
)
1107 checkIndex(index
, 0, tabs
.size());
1108 return ((Page
) tabs
.elementAt(index
)).getTitle();
1112 * This method returns the active icon given the index.
1114 * @param index The index of the tab.
1116 * @return The active icon for the tab.
1118 public Icon
getIconAt(int index
)
1120 checkIndex(index
, 0, tabs
.size());
1121 return ((Page
) tabs
.elementAt(index
)).getIcon();
1125 * This method returns the disabled icon given the index.
1127 * @param index The index of the tab.
1129 * @return The disabled icon for the tab.
1131 public Icon
getDisabledIconAt(int index
)
1133 checkIndex(index
, 0, tabs
.size());
1134 return ((Page
) tabs
.elementAt(index
)).getDisabledIcon();
1138 * This method returns the tooltip string for the tab.
1140 * @param index The index of the tab.
1142 * @return The tooltip string for the tab.
1144 public String
getToolTipTextAt(int index
)
1146 checkIndex(index
, 0, tabs
.size());
1147 return ((Page
) tabs
.elementAt(index
)).getTip();
1151 * This method returns the foreground color for the tab.
1153 * @param index The index of the tab.
1155 * @return The foreground color for the tab.
1157 public Color
getForegroundAt(int index
)
1159 checkIndex(index
, 0, tabs
.size());
1160 return ((Page
) tabs
.elementAt(index
)).getForeground();
1164 * This method returns the background color for the tab.
1166 * @param index The index of the tab.
1168 * @return The background color for the tab.
1170 public Color
getBackgroundAt(int index
)
1172 checkIndex(index
, 0, tabs
.size());
1173 return ((Page
) tabs
.elementAt(index
)).getBackground();
1177 * This method returns the component associated with the tab.
1179 * @param index The index of the tab.
1181 * @return The component associated with the tab.
1183 public Component
getComponentAt(int index
)
1185 checkIndex(index
, 0, tabs
.size());
1186 return ((Page
) tabs
.elementAt(index
)).getComponent();
1190 * This method returns whether this tab is enabled. Disabled tabs cannot be
1193 * @param index The index of the tab.
1195 * @return Whether the tab is enabled.
1197 public boolean isEnabledAt(int index
)
1199 checkIndex(index
, 0, tabs
.size());
1200 return ((Page
) tabs
.elementAt(index
)).isEnabled();
1204 * This method returns the mnemonic for the tab.
1206 * @param tabIndex The index of the tab.
1208 * @return The mnemonic for the tab.
1210 public int getMnemonicAt(int tabIndex
)
1212 checkIndex(tabIndex
, 0, tabs
.size());
1213 return ((Page
) tabs
.elementAt(tabIndex
)).getMnemonic();
1217 * This method returns the mnemonic index for the tab.
1219 * @param tabIndex The index of the tab.
1221 * @return The mnemonic index for the tab.
1223 public int getDisplayedMnemonicIndexAt(int tabIndex
)
1225 checkIndex(tabIndex
, 0, tabs
.size());
1226 return ((Page
) tabs
.elementAt(tabIndex
)).getDisplayedMnemonicIndex();
1230 * This method returns the bounds of the tab given the index.
1232 * @param index The index of the tab.
1234 * @return A rectangle describing the bounds of the tab.
1236 public Rectangle
getBoundsAt(int index
)
1238 checkIndex(index
, 0, tabs
.size());
1239 return ((TabbedPaneUI
) ui
).getTabBounds(this, index
);
1243 * This method sets the title of the tab.
1245 * @param index The index of the tab.
1246 * @param title The new title.
1248 public void setTitleAt(int index
, String title
)
1250 checkIndex(index
, 0, tabs
.size());
1251 ((Page
) tabs
.elementAt(index
)).setTitle(title
);
1255 * This method sets the icon of the tab.
1257 * @param index The index of the tab.
1258 * @param icon The new icon.
1260 public void setIconAt(int index
, Icon icon
)
1262 checkIndex(index
, 0, tabs
.size());
1263 ((Page
) tabs
.elementAt(index
)).setIcon(icon
);
1267 * This method sets the disabled icon of the tab.
1269 * @param index The index of the tab.
1270 * @param disabledIcon The new disabled icon.
1272 public void setDisabledIconAt(int index
, Icon disabledIcon
)
1274 checkIndex(index
, 0, tabs
.size());
1275 ((Page
) tabs
.elementAt(index
)).setDisabledIcon(disabledIcon
);
1279 * This method sets the tooltip text of the tab.
1281 * @param index The index of the tab.
1282 * @param toolTipText The tooltip text.
1284 public void setToolTipTextAt(int index
, String toolTipText
)
1286 checkIndex(index
, 0, tabs
.size());
1287 ((Page
) tabs
.elementAt(index
)).setTip(toolTipText
);
1291 * This method sets the background color of the tab.
1293 * @param index The index of the tab.
1294 * @param background The background color of the tab.
1296 public void setBackgroundAt(int index
, Color background
)
1298 checkIndex(index
, 0, tabs
.size());
1299 ((Page
) tabs
.elementAt(index
)).setBackground(background
);
1303 * This method sets the foreground color of the tab.
1305 * @param index The index of the tab.
1306 * @param foreground The foreground color of the tab.
1308 public void setForegroundAt(int index
, Color foreground
)
1310 checkIndex(index
, 0, tabs
.size());
1311 ((Page
) tabs
.elementAt(index
)).setForeground(foreground
);
1315 * This method sets whether the tab is enabled.
1317 * @param index The index of the tab.
1318 * @param enabled Whether the tab is enabled.
1320 public void setEnabledAt(int index
, boolean enabled
)
1322 checkIndex(index
, 0, tabs
.size());
1323 ((Page
) tabs
.elementAt(index
)).setEnabled(enabled
);
1327 * This method sets the component associated with the tab.
1329 * @param index The index of the tab.
1330 * @param component The component associated with the tab.
1332 public void setComponentAt(int index
, Component component
)
1334 checkIndex(index
, 0, tabs
.size());
1335 ((Page
) tabs
.elementAt(index
)).setComponent(component
);
1339 * This method sets the displayed mnemonic index of the tab.
1341 * @param tabIndex The index of the tab.
1342 * @param mnemonicIndex The mnemonic index.
1344 public void setDisplayedMnemonicIndexAt(int tabIndex
, int mnemonicIndex
)
1346 checkIndex(tabIndex
, 0, tabs
.size());
1347 ((Page
) tabs
.elementAt(tabIndex
)).setDisplayedMnemonicIndex(mnemonicIndex
);
1351 * This method sets the mnemonic for the tab.
1353 * @param tabIndex The index of the tab.
1354 * @param mnemonic The mnemonic.
1356 public void setMnemonicAt(int tabIndex
, int mnemonic
)
1358 checkIndex(tabIndex
, 0, tabs
.size());
1359 ((Page
) tabs
.elementAt(tabIndex
)).setMnemonic(mnemonic
);
1363 * This method finds the index of a tab given the title.
1365 * @param title The title that belongs to a tab.
1367 * @return The index of the tab that has the title or -1 if not found.
1369 public int indexOfTab(String title
)
1372 for (int i
= 0; i
< tabs
.size(); i
++)
1374 if (((Page
) tabs
.elementAt(i
)).getTitle().equals(title
))
1384 * This method finds the index of a tab given the icon.
1386 * @param icon The icon that belongs to a tab.
1388 * @return The index of the tab that has the icon or -1 if not found.
1390 public int indexOfTab(Icon icon
)
1393 for (int i
= 0; i
< tabs
.size(); i
++)
1395 if (((Page
) tabs
.elementAt(i
)).getIcon() == icon
)
1405 * This method finds the index of a tab given the component.
1407 * @param component A component associated with a tab.
1409 * @return The index of the tab that has this component or -1 if not found.
1411 public int indexOfComponent(Component component
)
1414 for (int i
= 0; i
< tabs
.size(); i
++)
1416 if (((Page
) tabs
.elementAt(i
)).getComponent() == component
)
1426 * This method returns a tab index given an (x,y) location. The origin of
1427 * the (x,y) pair will be the JTabbedPane's top left position. The tab
1428 * returned will be the one that contains the point. This method is
1429 * delegated to the UI.
1431 * @param x The x coordinate of the point.
1432 * @param y The y coordinate of the point.
1434 * @return The index of the tab that contains the point.
1436 public int indexAtLocation(int x
, int y
)
1438 return ((TabbedPaneUI
) ui
).tabForCoordinate(this, x
, y
);
1442 * This method returns the tooltip text given a mouse event.
1444 * @param event The mouse event.
1446 * @return The tool tip text that is associated with this mouse event.
1448 public String
getToolTipText(MouseEvent event
)
1450 int index
= indexAtLocation(event
.getX(), event
.getY());
1451 return ((Page
) tabs
.elementAt(index
)).getTip();
1455 * This method returns a string representation of this JTabbedPane. It is
1456 * mainly used for debugging purposes.
1458 * @return A string representation of this JTabbedPane.
1460 protected String
paramString()
1462 return "JTabbedPane";
1468 * @return DOCUMENT ME!
1470 public AccessibleContext
getAccessibleContext()
1472 if (accessibleContext
== null)
1473 accessibleContext
= new AccessibleJTabbedPane();
1474 return accessibleContext
;