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., 51 Franklin Street, Fifth Floor, 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 where only one component is displayed at
60 * a given time and the displayed component can be switched by clicking on
64 * Tabs can be oriented in several ways. They can be above, below, left and
65 * right of the component. Tabs can either wrap around (by creating multiple
66 * rows of tabs) or they can be scrolled (where only a subset of the tabs
67 * can be seen at once). More tabs can be added by calling the
68 * add/addTab/insertTab methods.
71 public class JTabbedPane extends JComponent implements Serializable,
76 * Accessibility support for <code>JTabbedPane</code>.
78 // FIXME: This inner class is a complete stub and must be implemented
80 protected class AccessibleJTabbedPane extends JComponent.AccessibleJComponent
81 implements AccessibleSelection, ChangeListener
84 * The serialization UID.
86 private static final long serialVersionUID = 7610530885966830483L;
89 * Creates a new AccessibleJTabbedPane object.
91 public AccessibleJTabbedPane()
97 * Receives notification when the selection state of the
98 * <code>JTabbedPane</code> changes.
100 * @param e the change event describing the change
102 public void stateChanged(ChangeEvent e)
104 // Implement this properly.
108 * Returns the accessible role of the <code>JTabbedPane</code>, which is
109 * {@link AccessibleRole#PAGE_TAB_LIST}.
111 * @return the accessible role of the <code>JTabbedPane</code>
113 public AccessibleRole getAccessibleRole()
119 * Returns the number of accessible child components of the
120 * <code>JTabbedPane</code>.
122 * @return the number of accessible child components of the
123 * <code>JTabbedPane</code>
125 public int getAccessibleChildrenCount()
131 * Returns the accessible child component at the specified index.
133 * @param i the index of the child component to fetch
135 * @return the accessible child component at the specified index
137 public Accessible getAccessibleChild(int i)
143 * Returns the current selection state of the <code>JTabbedPane</code>
144 * as AccessibleSelection object.
146 * @return the current selection state of the <code>JTabbedPane</code>
148 public AccessibleSelection getAccessibleSelection()
154 * Returns the accessible child component at the specified coordinates.
155 * If there is no child component at this location, then return the
156 * currently selected tab.
158 * @param p the coordinates at which to look up the child component
160 * @return the accessible child component at the specified coordinates or
161 * the currently selected tab if there is no child component at
164 public Accessible getAccessibleAt(Point p)
170 * The number of selected child components of the
171 * <code>JTabbedPane</code>. This will be <code>0</code> if the
172 * <code>JTabbedPane</code> has no children, or <code>1</code> otherwise,
173 * since there is always exactly one tab selected.
175 * @return number of selected child components of the
176 * <code>JTabbedPane</code>
178 public int getAccessibleSelectionCount()
186 * @param i DOCUMENT ME!
188 * @return DOCUMENT ME!
190 public Accessible getAccessibleSelection(int i)
198 * @param i DOCUMENT ME!
200 * @return DOCUMENT ME!
202 public boolean isAccessibleChildSelected(int i)
210 * @param i DOCUMENT ME!
212 public void addAccessibleSelection(int i)
214 // TODO: Implement this properly.
220 * @param i DOCUMENT ME!
222 public void removeAccessibleSelection(int i)
224 // TODO: Implement this properly.
230 public void clearAccessibleSelection()
232 // TODO: Implement this properly.
238 public void selectAllAccessibleSelection()
240 // TODO: Implement this properly.
245 * A helper class that listens for changes to the model.
247 protected class ModelListener implements ChangeListener, Serializable
250 private static final long serialVersionUID = 497359819958114132L;
253 * Creates a new ModelListener object.
255 protected ModelListener()
257 // Nothing to do here.
261 * This method is called whenever the model is changed.
263 * @param e The ChangeEvent that is passed from the model.
265 public void stateChanged(ChangeEvent e)
267 // Propagate to our listeners.
273 * A private class that holds all the information for each tab.
277 /** The tooltip string. */
280 /** The component associated with the tab. */
281 private Component component;
283 /** The active icon associated with the tab. */
284 private transient Icon icon;
286 /** The disabled icon associated with the tab. */
287 private transient Icon disabledIcon;
289 /** The tab's enabled status. */
290 private transient boolean enabled = true;
292 /** The string painted on the tab. */
293 private transient String title;
295 /** The background color of the tab. */
296 private transient Color bg;
298 /** The foreground color of the tab. */
299 private transient Color fg;
301 /** The mnemonic associated with the tab. */
302 private transient int mnemonicKey;
304 /** The index of the underlined character in the string. */
305 private transient int underlinedChar = -1;
308 * Creates a new data storage for the tab.
310 * @param title The string displayed on the tab.
311 * @param icon The active icon displayed on the tab.
312 * @param component The component associated with the tab.
313 * @param tip The tooltip associated with the tab.
315 protected Page(String title, Icon icon, Component component, String tip)
319 this.component = component;
324 * This method returns the component associated with the tab.
326 * @return The component associated with the tab.
328 public Component getComponent()
334 * This method sets the component associated with the tab.
336 * @param c The component associated with the tab.
338 public void setComponent(Component c)
340 int i = indexOfComponent(component);
341 insertTab(title, icon, c, tip, i);
347 * This method returns the tooltip string.
349 * @return The tooltip string.
351 public String getTip()
357 * This method sets the tooltip string.
359 * @param tip The tooltip string.
361 public void setTip(String tip)
367 * This method returns the background color.
369 * @return The background color.
371 public Color getBackground()
377 * This method sets the background color.
379 * @param background The background color.
381 public void setBackground(Color background)
387 * This method returns the foreground color.
389 * @return The foreground color.
391 public Color getForeground()
397 * This method sets the foreground color.
399 * @param foreground The foreground color.
401 public void setForeground(Color foreground)
407 * This method returns the title associated with the tab.
409 * @return The title of the tab.
411 public String getTitle()
417 private static final long serialVersionUID = 1614381073220130939L;
420 * This method sets the title of the tab.
422 * @param text The title of the tab.
424 public void setTitle(String text)
427 if (title != null && title.length() <= underlinedChar)
428 setDisplayedMnemonicIndex(title.length() - 1);
432 * This method returns the active icon.
434 * @return The active icon.
436 public Icon getIcon()
442 * This method sets the active icon.
444 * @param icon The active icon.
446 public void setIcon(Icon icon)
452 * This method returns the disabled icon.
454 * @return The disabled icon.
456 public Icon getDisabledIcon()
458 if (disabledIcon == null && icon instanceof ImageIcon)
459 setDisabledIcon(icon);
464 * This method sets the disabled icon.
466 * @param disabledIcon The disabled icon.
468 public void setDisabledIcon(Icon disabledIcon)
470 this.disabledIcon = disabledIcon;
474 * This method returns whether the tab is enabled.
476 * @return Whether the tab is enabled.
478 public boolean isEnabled()
484 * This method sets whether the tab is enabled.
486 * @param enabled Whether this tab is enabled.
488 public void setEnabled(boolean enabled)
490 this.enabled = enabled;
494 * This method returns the mnemonic.
496 * @return The mnemonic.
498 public int getMnemonic()
504 * This method sets the mnemonic. If the title is set, it will update the
507 * @param key The mnemonic.
509 public void setMnemonic(int key)
511 setMnemonic((char) key);
515 * This method sets the mnemonic. If the title is set, it will update the
518 * @param aChar The mnemonic.
520 public void setMnemonic(char aChar)
524 setDisplayedMnemonicIndex(title.indexOf(mnemonicKey));
528 * This method returns the mnemonicIndex.
530 * @return The mnemonicIndex.
532 public int getDisplayedMnemonicIndex()
534 return underlinedChar;
538 * This method sets the mnemonicIndex.
540 * @param index The mnemonicIndex.
542 * @throws IllegalArgumentException If index less than -1 || index greater
543 * or equal to title.length.
545 public void setDisplayedMnemonicIndex(int index)
546 throws IllegalArgumentException
548 if (index < -1 || title != null && index >= title.length())
549 throw new IllegalArgumentException();
551 if (title == null || mnemonicKey == 0 || (index > -1 && title.charAt(index) != mnemonicKey))
554 underlinedChar = index;
558 private static final long serialVersionUID = 1614381073220130939L;
560 /** The changeEvent used to fire changes to listeners. */
561 protected ChangeEvent changeEvent;
563 /** The listener that listens to the model. */
564 protected ChangeListener changeListener;
566 /** The model that describes this JTabbedPane. */
567 protected SingleSelectionModel model;
569 /** Indicates that the TabbedPane is in scrolling mode. */
570 public static final int SCROLL_TAB_LAYOUT = 1;
572 /** Indicates that the TabbedPane is in wrap mode. */
573 public static final int WRAP_TAB_LAYOUT = 0;
575 /** The current tabPlacement of the TabbedPane. */
576 protected int tabPlacement = SwingConstants.TOP;
578 /** The current tabLayoutPolicy of the TabbedPane. */
579 private transient int layoutPolicy;
581 /** The list of tabs associated with the TabbedPane. */
582 transient Vector tabs = new Vector();
585 * Creates a new JTabbedPane object with tabs on top and using wrap tab
590 this(SwingConstants.TOP, WRAP_TAB_LAYOUT);
594 * Creates a new JTabbedPane object using wrap tab layout and the given
595 * <code>tabPlacement</code>, where <code>tabPlacement</code> can be one
596 * of the following values: {@link #TOP}, {@link #BOTTOM}, {@link #LEFT} or
599 * @param tabPlacement where the tabs will be placed
601 public JTabbedPane(int tabPlacement)
603 this(tabPlacement, WRAP_TAB_LAYOUT);
607 * Creates a new JTabbedPane object with the given <code>tabPlacement</code>
608 * and <code>tabLayoutPolicy</code>. The <code>tabPlacement</code> can be one
609 * of the following values: {@link #TOP}, {@link #BOTTOM}, {@link #LEFT} or
610 * {@link #RIGHT}. The <code>tabLayoutPolicy</code> can be either
611 * {@link #SCROLL_TAB_LAYOUT} or {@link #WRAP_TAB_LAYOUT}.
613 * @param tabPlacement where the tabs will be placed
614 * @param tabLayoutPolicy the way tabs will be placed
616 * @throws IllegalArgumentException If tabLayoutPolicy or tabPlacement are
619 public JTabbedPane(int tabPlacement, int tabLayoutPolicy)
621 if (tabPlacement != TOP && tabPlacement != BOTTOM && tabPlacement != RIGHT
622 && tabPlacement != LEFT)
623 throw new IllegalArgumentException("tabPlacement is not valid.");
624 if (tabLayoutPolicy != SCROLL_TAB_LAYOUT
625 && tabLayoutPolicy != WRAP_TAB_LAYOUT)
626 throw new IllegalArgumentException("tabLayoutPolicy is not valid.");
627 this.tabPlacement = tabPlacement;
628 layoutPolicy = tabLayoutPolicy;
630 changeEvent = new ChangeEvent(this);
631 changeListener = createChangeListener();
633 model = new DefaultSingleSelectionModel();
634 model.addChangeListener(changeListener);
640 * This method returns the UI used to display the JTabbedPane.
642 * @return The UI used to display the JTabbedPane.
644 public TabbedPaneUI getUI()
646 return (TabbedPaneUI) ui;
650 * This method sets the UI used to display the JTabbedPane.
652 * @param ui The UI used to display the JTabbedPane.
654 public void setUI(TabbedPaneUI ui)
660 * This method restores the UI to the defaults given by the UIManager.
662 public void updateUI()
664 setUI((TabbedPaneUI) UIManager.getUI(this));
669 * This method returns a string identifier that is used to determine which
670 * UI will be used with the JTabbedPane.
672 * @return A string identifier for the UI.
674 public String getUIClassID()
676 return "TabbedPaneUI";
680 * This method creates a ChangeListener that is used to listen to the model
683 * @return A ChangeListener to listen to the model.
685 protected ChangeListener createChangeListener()
687 return new ModelListener();
691 * This method adds a ChangeListener to the JTabbedPane.
693 * @param l The ChangeListener to add.
695 public void addChangeListener(ChangeListener l)
697 listenerList.add(ChangeListener.class, l);
701 * This method removes a ChangeListener to the JTabbedPane.
703 * @param l The ChangeListener to remove.
705 public void removeChangeListener(ChangeListener l)
707 listenerList.remove(ChangeListener.class, l);
711 * This method fires a ChangeEvent to all the JTabbedPane's ChangeListeners.
713 protected void fireStateChanged()
715 Object[] changeListeners = listenerList.getListenerList();
716 if (changeEvent == null)
717 changeEvent = new ChangeEvent(this);
718 for (int i = changeListeners.length - 2; i >= 0; i -= 2)
720 if (changeListeners[i] == ChangeListener.class)
721 ((ChangeListener) changeListeners[i + 1]).stateChanged(changeEvent);
726 * This method returns all ChangeListeners registered with the JTabbedPane.
728 * @return The ChangeListeners registered with the JTabbedPane.
730 public ChangeListener[] getChangeListeners()
732 return (ChangeListener[]) super.getListeners(ChangeListener.class);
736 * This method returns the model used with the JTabbedPane.
738 * @return The JTabbedPane's model.
740 public SingleSelectionModel getModel()
746 * This method changes the model property of the JTabbedPane.
748 * @param model The new model to use with the JTabbedPane.
750 public void setModel(SingleSelectionModel model)
752 if (model != this.model)
754 SingleSelectionModel oldModel = this.model;
755 this.model.removeChangeListener(changeListener);
757 this.model.addChangeListener(changeListener);
758 firePropertyChange("model", oldModel, this.model);
763 * This method returns the tabPlacement.
765 * @return The tabPlacement used with the JTabbedPane.
767 public int getTabPlacement()
773 * This method changes the tabPlacement property of the JTabbedPane.
775 * @param tabPlacement The tabPlacement to use.
777 * @throws IllegalArgumentException If tabPlacement is not one of TOP,
778 * BOTTOM, LEFT, or RIGHT.
780 public void setTabPlacement(int tabPlacement)
782 if (tabPlacement != TOP && tabPlacement != BOTTOM && tabPlacement != RIGHT
783 && tabPlacement != LEFT)
784 throw new IllegalArgumentException("tabPlacement is not valid.");
785 if (tabPlacement != this.tabPlacement)
787 int oldPlacement = this.tabPlacement;
788 this.tabPlacement = tabPlacement;
789 firePropertyChange("tabPlacement", oldPlacement, this.tabPlacement);
794 * This method returns the tabLayoutPolicy.
796 * @return The tabLayoutPolicy.
798 public int getTabLayoutPolicy()
804 * This method changes the tabLayoutPolicy property of the JTabbedPane.
806 * @param tabLayoutPolicy The tabLayoutPolicy to use.
808 * @throws IllegalArgumentException If tabLayoutPolicy is not one of
809 * SCROLL_TAB_LAYOUT or WRAP_TAB_LAYOUT.
811 public void setTabLayoutPolicy(int tabLayoutPolicy)
813 if (tabLayoutPolicy != SCROLL_TAB_LAYOUT
814 && tabLayoutPolicy != WRAP_TAB_LAYOUT)
815 throw new IllegalArgumentException("tabLayoutPolicy is not valid.");
816 if (tabLayoutPolicy != layoutPolicy)
818 int oldPolicy = layoutPolicy;
819 layoutPolicy = tabLayoutPolicy;
820 firePropertyChange("tabLayoutPolicy", oldPolicy, layoutPolicy);
825 * This method returns the index of the tab that is currently selected.
827 * @return The index of the selected tab.
829 public int getSelectedIndex()
831 return model.getSelectedIndex();
835 * This method checks the index.
837 * @param index The index to check.
838 * @param start DOCUMENT ME!
839 * @param end DOCUMENT ME!
841 * @throws IndexOutOfBoundsException DOCUMENT ME!
843 private void checkIndex(int index, int start, int end)
845 if (index < start || index >= end)
846 throw new IndexOutOfBoundsException("Index < " + start + " || Index >= "
851 * This method sets the selected index. This method will hide the old
852 * component and show the new component.
854 * @param index The index to set it at.
856 public void setSelectedIndex(int index)
858 checkIndex(index, -1, tabs.size());
859 if (index != getSelectedIndex())
861 if (getSelectedIndex() != -1 && getSelectedComponent() != null)
862 getSelectedComponent().hide();
863 if (index != -1 && getComponentAt(index) != null)
864 getComponentAt(index).show();
865 model.setSelectedIndex(index);
870 * This method returns the component at the selected index.
872 * @return The component at the selected index.
874 public Component getSelectedComponent()
876 return getComponentAt(getSelectedIndex());
880 * This method sets the component at the selected index.
882 * @param c The component associated with the selected index.
884 public void setSelectedComponent(Component c)
886 if (c.getParent() == this)
887 setSelectedIndex(indexOfComponent(c));
889 setComponentAt(getSelectedIndex(), c);
893 * This method inserts tabs into JTabbedPane. This includes adding the
894 * component to the JTabbedPane and hiding it.
896 * @param title the title of the tab; may be <code>null</code>
897 * @param icon the tab's icon; may be <code>null</code>
898 * @param component the component associated with the tab
899 * @param tip the tooltip for the tab
900 * @param index the index to insert the tab at
902 public void insertTab(String title, Icon icon, Component component,
903 String tip, int index)
907 Page p = new Page(title, icon, component, tip);
908 tabs.insertElementAt(p, index);
910 // Hide the component so we don't see it. Do it before we parent it
911 // so we don't trigger a repaint.
912 if (component != null)
915 super.add(component);
918 if (getSelectedIndex() == -1)
926 * This method adds a tab to the JTabbedPane.
928 * @param title the title of the tab; may be <code>null</code>
929 * @param icon the icon for the tab; may be <code>null</code>
930 * @param component the associated component
931 * @param tip the associated tooltip
933 public void addTab(String title, Icon icon, Component component, String tip)
935 insertTab(title, icon, component, tip, tabs.size());
939 * This method adds a tab to the JTabbedPane.
941 * @param title the title of the tab; may be <code>null</code>
942 * @param icon the icon for the tab; may be <code>null</code>
943 * @param component the associated component
945 public void addTab(String title, Icon icon, Component component)
947 insertTab(title, icon, component, null, tabs.size());
951 * This method adds a tab to the JTabbedPane.
953 * @param title the title of the tab; may be <code>null</code>
954 * @param component the associated component
956 public void addTab(String title, Component component)
958 insertTab(title, null, component, null, tabs.size());
962 * This method adds a tab to the JTabbedPane. The title of the tab is the
963 * Component's name. If the Component is an instance of UIResource, it
964 * doesn't add the tab and instead add the component directly to the
967 * @param component The associated component.
969 * @return The Component that was added.
971 public Component add(Component component)
973 if (component instanceof UIResource)
974 super.add(component);
976 insertTab(component.getName(), null, component, null, tabs.size());
982 * This method adds a tab to the JTabbedPane. If the Component is an
983 * instance of UIResource, it doesn't add the tab and instead add the
984 * component directly to the JTabbedPane.
986 * @param title the title of the tab; may be <code>null</code>
987 * @param component the associated component
989 * @return The Component that was added.
991 public Component add(String title, Component component)
993 if (component instanceof UIResource)
994 super.add(component);
996 insertTab(title, null, component, null, tabs.size());
1001 * This method adds a tab to the JTabbedPane. If the Component is an
1002 * instance of UIResource, it doesn't add the tab and instead add the
1003 * component directly to the JTabbedPane.
1005 * @param component The associated component.
1006 * @param index The index to insert the tab at.
1008 * @return The Component that was added.
1010 public Component add(Component component, int index)
1012 if (component instanceof UIResource)
1013 super.add(component);
1015 insertTab(component.getName(), null, component, null, index);
1020 * This method adds a tab to the JTabbedPane. If the Component is an
1021 * instance of UIResource, it doesn't add the tab and instead add the
1022 * component directly to the JTabbedPane. If the constraints object is an
1023 * icon, it will be used as the tab's icon. If the constraints object is a
1024 * string, we will use it as the title.
1026 * @param component The associated component.
1027 * @param constraints The constraints object.
1029 public void add(Component component, Object constraints)
1031 add(component, constraints, tabs.size());
1035 * This method adds a tab to the JTabbedPane. If the Component is an
1036 * instance of UIResource, it doesn't add the tab and instead add the
1037 * component directly to the JTabbedPane. If the constraints object is an
1038 * icon, it will be used as the tab's icon. If the constraints object is a
1039 * string, we will use it as the title.
1041 * @param component The associated component.
1042 * @param constraints The constraints object.
1043 * @param index The index to insert the tab at.
1045 public void add(Component component, Object constraints, int index)
1047 if (component instanceof UIResource)
1048 super.add(component);
1051 if (constraints instanceof String)
1052 insertTab((String) constraints, null, component, null, index);
1054 insertTab(component.getName(),
1055 (constraints instanceof Icon) ? (Icon) constraints : null,
1056 component, null, index);
1061 * Removes the tab at index. After the component associated with
1062 * index is removed, its visibility is reset to true to ensure it
1063 * will be visible if added to other containers.
1065 * @param index The index of the tab to remove.
1067 public void removeTabAt(int index)
1069 checkIndex(index, 0, tabs.size());
1071 getComponentAt(index).show();
1075 * Removes the specified Component from the JTabbedPane.
1077 * @param component The Component to remove.
1079 public void remove(Component component)
1081 super.remove(component);
1085 * Removes the tab and component which corresponds to the specified index.
1087 * @param index The index of the tab to remove.
1089 public void remove(int index)
1091 remove(getComponentAt(index));
1096 * This method removes all tabs and associated components from the
1099 public void removeAll()
1101 for (int i = tabs.size() - 1; i >= 0; i--)
1106 * This method returns how many tabs are in the JTabbedPane.
1108 * @return The number of tabs in the JTabbedPane.
1110 public int getTabCount()
1116 * This method returns the number of runs used to paint the JTabbedPane.
1118 * @return The number of runs.
1120 public int getTabRunCount()
1122 return ((TabbedPaneUI) ui).getTabRunCount(this);
1126 * This method returns the tab title given the index.
1128 * @param index The index of the tab.
1130 * @return The title for the tab.
1132 public String getTitleAt(int index)
1134 checkIndex(index, 0, tabs.size());
1135 return ((Page) tabs.elementAt(index)).getTitle();
1139 * This method returns the active icon given the index.
1141 * @param index The index of the tab.
1143 * @return The active icon for the tab.
1145 public Icon getIconAt(int index)
1147 checkIndex(index, 0, tabs.size());
1148 return ((Page) tabs.elementAt(index)).getIcon();
1152 * This method returns the disabled icon given the index.
1154 * @param index The index of the tab.
1156 * @return The disabled icon for the tab.
1158 public Icon getDisabledIconAt(int index)
1160 checkIndex(index, 0, tabs.size());
1161 return ((Page) tabs.elementAt(index)).getDisabledIcon();
1165 * This method returns the tooltip string for the tab.
1167 * @param index The index of the tab.
1169 * @return The tooltip string for the tab.
1171 public String getToolTipTextAt(int index)
1173 checkIndex(index, 0, tabs.size());
1174 return ((Page) tabs.elementAt(index)).getTip();
1178 * This method returns the foreground color for the tab.
1180 * @param index The index of the tab.
1182 * @return The foreground color for the tab.
1184 public Color getForegroundAt(int index)
1186 checkIndex(index, 0, tabs.size());
1187 return ((Page) tabs.elementAt(index)).getForeground();
1191 * This method returns the background color for the tab.
1193 * @param index The index of the tab.
1195 * @return The background color for the tab.
1197 public Color getBackgroundAt(int index)
1199 checkIndex(index, 0, tabs.size());
1200 return ((Page) tabs.elementAt(index)).getBackground();
1204 * This method returns the component associated with the tab.
1206 * @param index The index of the tab.
1208 * @return The component associated with the tab.
1210 public Component getComponentAt(int index)
1212 checkIndex(index, 0, tabs.size());
1213 return ((Page) tabs.elementAt(index)).getComponent();
1217 * This method returns whether this tab is enabled. Disabled tabs cannot be
1220 * @param index The index of the tab.
1222 * @return Whether the tab is enabled.
1224 public boolean isEnabledAt(int index)
1226 checkIndex(index, 0, tabs.size());
1227 return ((Page) tabs.elementAt(index)).isEnabled();
1231 * This method returns the mnemonic for the tab.
1233 * @param tabIndex The index of the tab.
1235 * @return The mnemonic for the tab.
1237 public int getMnemonicAt(int tabIndex)
1239 checkIndex(tabIndex, 0, tabs.size());
1240 return ((Page) tabs.elementAt(tabIndex)).getMnemonic();
1244 * This method returns the mnemonic index for the tab.
1246 * @param tabIndex The index of the tab.
1248 * @return The mnemonic index for the tab.
1250 public int getDisplayedMnemonicIndexAt(int tabIndex)
1252 checkIndex(tabIndex, 0, tabs.size());
1253 return ((Page) tabs.elementAt(tabIndex)).getDisplayedMnemonicIndex();
1257 * This method returns the bounds of the tab given the index.
1259 * @param index The index of the tab.
1261 * @return A rectangle describing the bounds of the tab.
1263 public Rectangle getBoundsAt(int index)
1265 checkIndex(index, 0, tabs.size());
1266 return ((TabbedPaneUI) ui).getTabBounds(this, index);
1270 * This method sets the title of the tab.
1272 * @param index The index of the tab.
1273 * @param title The new title.
1275 public void setTitleAt(int index, String title)
1277 checkIndex(index, 0, tabs.size());
1278 ((Page) tabs.elementAt(index)).setTitle(title);
1282 * This method sets the icon of the tab.
1284 * @param index The index of the tab.
1285 * @param icon The new icon.
1287 public void setIconAt(int index, Icon icon)
1289 checkIndex(index, 0, tabs.size());
1290 ((Page) tabs.elementAt(index)).setIcon(icon);
1294 * This method sets the disabled icon of the tab.
1296 * @param index The index of the tab.
1297 * @param disabledIcon The new disabled icon.
1299 public void setDisabledIconAt(int index, Icon disabledIcon)
1301 checkIndex(index, 0, tabs.size());
1302 ((Page) tabs.elementAt(index)).setDisabledIcon(disabledIcon);
1306 * This method sets the tooltip text of the tab.
1308 * @param index The index of the tab.
1309 * @param toolTipText The tooltip text.
1311 public void setToolTipTextAt(int index, String toolTipText)
1313 checkIndex(index, 0, tabs.size());
1314 ((Page) tabs.elementAt(index)).setTip(toolTipText);
1318 * This method sets the background color of the tab.
1320 * @param index The index of the tab.
1321 * @param background The background color of the tab.
1323 public void setBackgroundAt(int index, Color background)
1325 checkIndex(index, 0, tabs.size());
1326 ((Page) tabs.elementAt(index)).setBackground(background);
1330 * This method sets the foreground color of the tab.
1332 * @param index The index of the tab.
1333 * @param foreground The foreground color of the tab.
1335 public void setForegroundAt(int index, Color foreground)
1337 checkIndex(index, 0, tabs.size());
1338 ((Page) tabs.elementAt(index)).setForeground(foreground);
1342 * This method sets whether the tab is enabled.
1344 * @param index The index of the tab.
1345 * @param enabled Whether the tab is enabled.
1347 public void setEnabledAt(int index, boolean enabled)
1349 checkIndex(index, 0, tabs.size());
1350 ((Page) tabs.elementAt(index)).setEnabled(enabled);
1354 * This method sets the component associated with the tab.
1356 * @param index The index of the tab.
1357 * @param component The component associated with the tab.
1359 public void setComponentAt(int index, Component component)
1361 checkIndex(index, 0, tabs.size());
1362 ((Page) tabs.elementAt(index)).setComponent(component);
1366 * This method sets the displayed mnemonic index of the tab.
1368 * @param tabIndex The index of the tab.
1369 * @param mnemonicIndex The mnemonic index.
1371 public void setDisplayedMnemonicIndexAt(int tabIndex, int mnemonicIndex)
1373 checkIndex(tabIndex, 0, tabs.size());
1374 ((Page) tabs.elementAt(tabIndex)).setDisplayedMnemonicIndex(mnemonicIndex);
1378 * This method sets the mnemonic for the tab.
1380 * @param tabIndex The index of the tab.
1381 * @param mnemonic The mnemonic.
1383 public void setMnemonicAt(int tabIndex, int mnemonic)
1385 checkIndex(tabIndex, 0, tabs.size());
1386 ((Page) tabs.elementAt(tabIndex)).setMnemonic(mnemonic);
1390 * This method finds the index of a tab given the title.
1392 * @param title The title that belongs to a tab.
1394 * @return The index of the tab that has the title or -1 if not found.
1396 public int indexOfTab(String title)
1399 for (int i = 0; i < tabs.size(); i++)
1401 if (((Page) tabs.elementAt(i)).getTitle().equals(title))
1411 * This method finds the index of a tab given the icon.
1413 * @param icon The icon that belongs to a tab.
1415 * @return The index of the tab that has the icon or -1 if not found.
1417 public int indexOfTab(Icon icon)
1420 for (int i = 0; i < tabs.size(); i++)
1422 if (((Page) tabs.elementAt(i)).getIcon() == icon)
1432 * This method finds the index of a tab given the component.
1434 * @param component A component associated with a tab.
1436 * @return The index of the tab that has this component or -1 if not found.
1438 public int indexOfComponent(Component component)
1441 for (int i = 0; i < tabs.size(); i++)
1443 if (((Page) tabs.elementAt(i)).getComponent() == component)
1453 * This method returns a tab index given an (x,y) location. The origin of
1454 * the (x,y) pair will be the JTabbedPane's top left position. The tab
1455 * returned will be the one that contains the point. This method is
1456 * delegated to the UI.
1458 * @param x The x coordinate of the point.
1459 * @param y The y coordinate of the point.
1461 * @return The index of the tab that contains the point.
1463 public int indexAtLocation(int x, int y)
1465 return ((TabbedPaneUI) ui).tabForCoordinate(this, x, y);
1469 * This method returns the tooltip text given a mouse event.
1471 * @param event The mouse event.
1473 * @return The tool tip text that is associated with this mouse event.
1475 public String getToolTipText(MouseEvent event)
1477 int index = indexAtLocation(event.getX(), event.getY());
1478 return ((Page) tabs.elementAt(index)).getTip();
1482 * This method returns a string representation of this JTabbedPane. It is
1483 * mainly used for debugging purposes.
1485 * @return A string representation of this JTabbedPane.
1487 protected String paramString()
1489 return "JTabbedPane";
1495 * @return DOCUMENT ME!
1497 public AccessibleContext getAccessibleContext()
1499 if (accessibleContext == null)
1500 accessibleContext = new AccessibleJTabbedPane();
1501 return accessibleContext;