⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jtabbedpane.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    }    /**     * This method sets the mnemonic. If the title is set, it will update the     * mnemonicIndex.     *     * @param key The mnemonic.     */    public void setMnemonic(int key)    {      setMnemonic((char) key);    }    /**     * This method sets the mnemonic. If the title is set, it will update the     * mnemonicIndex.     *     * @param aChar The mnemonic.     */    public void setMnemonic(char aChar)    {      mnemonicKey = aChar;      if (title != null)	setDisplayedMnemonicIndex(title.indexOf(mnemonicKey));    }    /**     * This method returns the mnemonicIndex.     *     * @return The mnemonicIndex.     */    public int getDisplayedMnemonicIndex()    {      return underlinedChar;    }    /**     * This method sets the mnemonicIndex.     *     * @param index The mnemonicIndex.     *     * @throws IllegalArgumentException If index less than -1 || index greater     *         or equal to title.length.     */    public void setDisplayedMnemonicIndex(int index)      throws IllegalArgumentException    {      if (index < -1 || title != null && index >= title.length())	throw new IllegalArgumentException();      if (title == null || mnemonicKey == 0 || (index > -1 && title.charAt(index) != mnemonicKey))	index = -1;      underlinedChar = index;    }  }  private static final long serialVersionUID = 1614381073220130939L;  /** The changeEvent used to fire changes to listeners. */  protected ChangeEvent changeEvent;  /** The listener that listens to the model. */  protected ChangeListener changeListener;  /** The model that describes this JTabbedPane. */  protected SingleSelectionModel model;  /** Indicates that the TabbedPane is in scrolling mode. */  public static final int SCROLL_TAB_LAYOUT = 1;  /** Indicates that the TabbedPane is in wrap mode. */  public static final int WRAP_TAB_LAYOUT = 0;  /** The current tabPlacement of the TabbedPane. */  protected int tabPlacement = SwingConstants.TOP;  /** The current tabLayoutPolicy of the TabbedPane. */  private transient int layoutPolicy;  /** The list of tabs associated with the TabbedPane. */  transient Vector tabs = new Vector();  /**   * Creates a new JTabbedPane object with tabs on top and using wrap tab   * layout.   */  public JTabbedPane()  {    this(SwingConstants.TOP, WRAP_TAB_LAYOUT);  }  /**   * Creates a new JTabbedPane object using wrap tab layout  and the given   * tabPlacement.   *   * @param tabPlacement Where the tabs will be placed.   */  public JTabbedPane(int tabPlacement)  {    this(tabPlacement, WRAP_TAB_LAYOUT);  }  /**   * Creates a new JTabbedPane object with the given tabPlacement and   * tabLayoutPolicy.   *   * @param tabPlacement Where the tabs will be placed.   * @param tabLayoutPolicy The way tabs will be placed.   *   * @throws IllegalArgumentException If tabLayoutPolicy or tabPlacement are   *         not valid.   */  public JTabbedPane(int tabPlacement, int tabLayoutPolicy)  {    if (tabPlacement != TOP && tabPlacement != BOTTOM && tabPlacement != RIGHT        && tabPlacement != LEFT)      throw new IllegalArgumentException("tabPlacement is not valid.");    if (tabLayoutPolicy != SCROLL_TAB_LAYOUT        && tabLayoutPolicy != WRAP_TAB_LAYOUT)      throw new IllegalArgumentException("tabLayoutPolicy is not valid.");    this.tabPlacement = tabPlacement;    layoutPolicy = tabLayoutPolicy;        changeEvent = new ChangeEvent(this);    changeListener = createChangeListener();    model = new DefaultSingleSelectionModel();    model.addChangeListener(changeListener);    updateUI();  }  /**   * This method returns the UI used to display the JTabbedPane.   *   * @return The UI used to display the JTabbedPane.   */  public TabbedPaneUI getUI()  {    return (TabbedPaneUI) ui;  }  /**   * This method sets the UI used to display the JTabbedPane.   *   * @param ui The UI used to display the JTabbedPane.   */  public void setUI(TabbedPaneUI ui)  {    super.setUI(ui);  }  /**   * This method restores the UI to the defaults given by the UIManager.   */  public void updateUI()  {    setUI((TabbedPaneUI) UIManager.getUI(this));    invalidate();  }  /**   * This method returns a string identifier that  is used to determine which   * UI will be used with  the JTabbedPane.   *   * @return A string identifier for the UI.   */  public String getUIClassID()  {    return "TabbedPaneUI";  }  /**   * This method creates a ChangeListener that is used to  listen to the model   * for events.   *   * @return A ChangeListener to listen to the model.   */  protected ChangeListener createChangeListener()  {    return new ModelListener();  }  /**   * This method adds a ChangeListener to the JTabbedPane.   *   * @param l The ChangeListener to add.   */  public void addChangeListener(ChangeListener l)  {    listenerList.add(ChangeListener.class, l);  }  /**   * This method removes a ChangeListener to the JTabbedPane.   *   * @param l The ChangeListener to remove.   */  public void removeChangeListener(ChangeListener l)  {    listenerList.remove(ChangeListener.class, l);  }  /**   * This method fires a ChangeEvent to all the JTabbedPane's ChangeListeners.   */  protected void fireStateChanged()  {    Object[] changeListeners = listenerList.getListenerList();    if (changeEvent == null)      changeEvent = new ChangeEvent(this);    for (int i = changeListeners.length - 2; i >= 0; i -= 2)      {	if (changeListeners[i] == ChangeListener.class)	  ((ChangeListener) changeListeners[i + 1]).stateChanged(changeEvent);      }  }  /**   * This method returns all ChangeListeners registered with the JTabbedPane.   *   * @return The ChangeListeners registered with the JTabbedPane.   */  public ChangeListener[] getChangeListeners()  {    return (ChangeListener[]) super.getListeners(ChangeListener.class);  }  /**   * This method returns the model used with the JTabbedPane.   *   * @return The JTabbedPane's model.   */  public SingleSelectionModel getModel()  {    return model;  }  /**   * This method changes the model property of the JTabbedPane.   *   * @param model The new model to use with the JTabbedPane.   */  public void setModel(SingleSelectionModel model)  {    if (model != this.model)      {	SingleSelectionModel oldModel = this.model;	this.model.removeChangeListener(changeListener);	this.model = model;	this.model.addChangeListener(changeListener);	firePropertyChange("model", oldModel, this.model);      }  }  /**   * This method returns the tabPlacement.   *   * @return The tabPlacement used with the JTabbedPane.   */  public int getTabPlacement()  {    return tabPlacement;  }  /**   * This method changes the tabPlacement property of the JTabbedPane.   *   * @param tabPlacement The tabPlacement to use.   *   * @throws IllegalArgumentException If tabPlacement is not one of TOP,   *         BOTTOM, LEFT, or RIGHT.   */  public void setTabPlacement(int tabPlacement)  {    if (tabPlacement != TOP && tabPlacement != BOTTOM && tabPlacement != RIGHT        && tabPlacement != LEFT)      throw new IllegalArgumentException("tabPlacement is not valid.");    if (tabPlacement != this.tabPlacement)      {	int oldPlacement = this.tabPlacement;	this.tabPlacement = tabPlacement;	firePropertyChange("tabPlacement", oldPlacement, this.tabPlacement);      }  }  /**   * This method returns the tabLayoutPolicy.   *   * @return The tabLayoutPolicy.   */  public int getTabLayoutPolicy()  {    return layoutPolicy;  }  /**   * This method changes the tabLayoutPolicy property of the JTabbedPane.   *   * @param tabLayoutPolicy The tabLayoutPolicy to use.   *   * @throws IllegalArgumentException If tabLayoutPolicy is not one of   *         SCROLL_TAB_LAYOUT or WRAP_TAB_LAYOUT.   */  public void setTabLayoutPolicy(int tabLayoutPolicy)  {    if (tabLayoutPolicy != SCROLL_TAB_LAYOUT        && tabLayoutPolicy != WRAP_TAB_LAYOUT)      throw new IllegalArgumentException("tabLayoutPolicy is not valid.");    if (tabLayoutPolicy != layoutPolicy)      {	int oldPolicy = layoutPolicy;	layoutPolicy = tabLayoutPolicy;	firePropertyChange("tabLayoutPolicy", oldPolicy, layoutPolicy);      }  }  /**   * This method returns the index of the tab that is currently selected.   *   * @return The index of the selected tab.   */  public int getSelectedIndex()  {    return model.getSelectedIndex();  }  /**   * This method checks the index.   *   * @param index The index to check.   * @param start DOCUMENT ME!   * @param end DOCUMENT ME!   *   * @throws IndexOutOfBoundsException DOCUMENT ME!   */  private void checkIndex(int index, int start, int end)  {    if (index < start || index >= end)      throw new IndexOutOfBoundsException("Index < " + start + " || Index >= "                                          + end);  }  /**   * 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()  {    return getComponentAt(getSelectedIndex());  }  /**   * This method sets the component at the selected index.   *   * @param c The component associated with the selected index.   */  public void setSelectedComponent(Component c)  {    if (c.getParent() == this)      setSelectedIndex(indexOfComponent(c));    else      setComponentAt(getSelectedIndex(), c);  }  /**   * This method inserts tabs into JTabbedPane. This includes adding the   * component to the JTabbedPane and hiding it.   *   * @param title the title of the tab; may be <code>null</code>   * @param icon the tab's icon; may be <code>null</code>   * @param component the component associated with the tab   * @param tip the tooltip for the tab   * @param index the index to insert the tab at   */  public void insertTab(String title, Icon icon, Component component,                        String tip, int index)  {    if (title == null)      title = "";    Page p = new Page(title, icon, component, tip);    tabs.insertElementAt(p, index);    // Hide the component so we don't see it. Do it before we parent it    // so we don't trigger a repaint.    if (component != null)      {	component.hide();	super.add(component);      }    if (getSelectedIndex() == -1)      setSelectedIndex(0);    layout();    repaint();  }  /**   * This method adds a tab to the JTabbedPane.   *   * @param title the title of the tab; may be <code>null</code>   * @param icon the icon for the tab; may be <code>null</code>   * @param component the associated component   * @param tip the associated tooltip   */  public void addTab(String title, Icon icon, Component component, String tip)  {    insertTab(title, icon, component, tip, tabs.size());  }  /**   * This method adds a tab to the JTabbedPane.   *   * @param title the title of the tab; may be <code>null</code>   * @param icon the icon for the tab; may be <code>null</code>   * @param component the associated component   */  public void addTab(String title, Icon icon, Component component)  {    insertTab(title, icon, component, null, tabs.size());  }  /**   * This method adds a tab to the JTabbedPane.   *   * @param title the title of the tab; may be <code>null</code>   * @param component the associated component   */  public void addTab(String title, Component component)  {    insertTab(title, null, component, null, tabs.size());  }  /**   * This method adds a tab to the JTabbedPane. The title of the tab is the   * Component's name. If the Component is an instance of UIResource, it   * doesn't add the tab and instead add the component directly to the   * JTabbedPane.   *   * @param component The associated component.   *   * @return The Component that was added.   */  public Component add(Component component)  {    if (component instanceof UIResource)      super.add(component);    else      insertTab(component.getName(), null, component, null, tabs.size());        return component;  }  /**   * This method adds a tab to the JTabbedPane. If the Component is an   * instance of UIResource, it doesn't add the tab and instead add the   * component directly to the JTabbedPane.   *   * @param title the title of the tab; may be <code>null</code>   * @param component the associated component   *   * @return The Component that was added.   */  public Component add(String title, Component component)  {    if (component instanceof UIResource)      super.add(component);    else      insertTab(title, null, component, null, tabs.size());    return component;  }  /**   * This method adds a tab to the JTabbedPane. If the Component is an   * instance of UIResource, it doesn't add the tab and instead add the   * component directly to the JTabbedPane.   *   * @param component The associated component.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -