Class GTabPanel<T>
- Type Parameters:
T
- The type of values in the tab panel.
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
If there are too many tabs to display horizontally, a "hidden tabs" control will be displayed that when activated, will display a popup dialog with a scrollable list of all possible values.
It also supports the idea of a highlighted tab which represents a value that is not selected, but is a candidate to be selected. For example, when the tab panel has focus, using the left and right arrows will highlight different tabs. Then pressing enter will cause the highlighted tab to be selected.
The clients of this component can also supply functions for customizing the name, icon, and tooltip for values. They can also add consumers for when the selected value changes or a value is removed from the tab panel. Clients can also install a predicate for the close tab action so they can process it before the value is removed and possibly veto the remove.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a new tab to the panel for the given value.void
Add tabs for each value in the given list.Returns a list of all tab values that are not visible.Returns the currently highlighted tab if a tab is highlighted.Returns the currently selected tab.int
Returns the total number of tabs both visible and hidden.Returns a list of values for all the tabs in the panel.getValueFor
(MouseEvent event) Returns the value of the tab that generated the given mouse event.Returns a list of all tab values that are visible.boolean
Returns true if not all tabs are visible in the tab panel.void
highlightNextPreviousTab
(boolean forward) Moves the highlight to the next or previous tab from the current highlight.void
highlightTab
(T value) Sets the tab for the given value to be highlighted.boolean
Returns true if the popup tab list is showing.boolean
isVisibleTab
(T value) Returns true if the tab for the given value is visible on the tab panel.void
refreshTab
(T value) Informs the tab panel that some displayable property about the value has changed and the tabs label, icon, and tooltip need to be updated.void
Removes the tab with the given value.void
removeTabs
(Collection<T> values) Remove tabs for all values in the given list.void
Makes the tab for the given value be the selected tab.void
setCloseTabConsumer
(Consumer<T> closeTabConsumer) Sets the predicate that will be called before removing a tab via the gui close control.void
setIconFunction
(Function<T, Icon> iconFunction) Sets a function to be used to generated an icon for a given value.void
setIgnoreFocus
(boolean ignoreFocusLost) void
setNameFunction
(Function<T, String> nameFunction) Sets a function to be used to generated a display name for a given value.void
setSelectedTabConsumer
(Consumer<T> selectedTabConsumer) Sets the consumer to be notified when the selected tab changes.void
setShowTabsAlways
(boolean b) Sets whether or not tabs should be display when there is only one tab.void
setToolTipFunction
(Function<T, String> toolTipFunction) Sets a function to be used to generated an tooltip for a given value.void
showTabList
(boolean show) Shows a popup dialog window with a filterable and scrollable list of all tab values.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
GTabPanel
Constructor- Parameters:
tabTypeName
- the name of the type of values in the tab panel. This will be used to set accessible descriptions.
-
-
Method Details
-
addTab
Add a new tab to the panel for the given value.- Parameters:
value
- the value for the new tab
-
addTabs
Add tabs for each value in the given list.- Parameters:
values
- the values to add tabs for
-
removeTab
Removes the tab with the given value.- Parameters:
value
- the value for which to remove its tab
-
removeTabs
Remove tabs for all values in the given list.- Parameters:
values
- the values to remove from the tab panel
-
getSelectedTabValue
Returns the currently selected tab. If the panel is not empty, there will always be a selected tab.- Returns:
- the currently selected tab or null if the panel is empty
-
getHighlightedTabValue
Returns the currently highlighted tab if a tab is highlighted. Note: the selected tab can never be highlighted.- Returns:
- the currently highlighted tab or null if no tab is highligted
-
selectTab
Makes the tab for the given value be the selected tab.- Parameters:
value
- the value whose tab is to be selected
-
getTabValues
Returns a list of values for all the tabs in the panel.- Returns:
- a list of values for all the tabs in the panel
-
isVisibleTab
Returns true if the tab for the given value is visible on the tab panel.- Parameters:
value
- the value to test if visible- Returns:
- true if the tab for the given value is visible on the tab panel
-
getTabCount
public int getTabCount()Returns the total number of tabs both visible and hidden.- Returns:
- the total number of tabs both visible and hidden.
-
highlightTab
Sets the tab for the given value to be highlighted. If the value is selected, then the highlighted tab will be set to null.- Parameters:
value
- the value to highlight its tab
-
hasHiddenTabs
public boolean hasHiddenTabs()Returns true if not all tabs are visible in the tab panel.- Returns:
- true if not all tabs are visible in the tab panel
-
getHiddenTabs
Returns a list of all tab values that are not visible.- Returns:
- a list of all tab values that are not visible
-
getVisibleTabs
Returns a list of all tab values that are visible.- Returns:
- a list of all tab values that are visible
-
showTabList
public void showTabList(boolean show) Shows a popup dialog window with a filterable and scrollable list of all tab values.- Parameters:
show
- true to show the popup list, false to close the popup list
-
highlightNextPreviousTab
public void highlightNextPreviousTab(boolean forward) Moves the highlight to the next or previous tab from the current highlight. If there is no current highlight, it will highlight the next or previous tab from the selected tab.- Parameters:
forward
- true moves the highlight to the right; otherwise move the highlight to the left
-
refreshTab
Informs the tab panel that some displayable property about the value has changed and the tabs label, icon, and tooltip need to be updated.- Parameters:
value
- the value that has changed
-
setNameFunction
Sets a function to be used to generated a display name for a given value. The display name is used in the tab, the filter, and the accessible description.- Parameters:
nameFunction
- the function to generate display names for values
-
setIconFunction
Sets a function to be used to generated an icon for a given value.- Parameters:
iconFunction
- the function to generate icons for values
-
setToolTipFunction
Sets a function to be used to generated an tooltip for a given value.- Parameters:
toolTipFunction
- the function to generate tooltips for values
-
setCloseTabConsumer
Sets the predicate that will be called before removing a tab via the gui close control. Note that that tab panel's default action is to remove the tab value, but if you set your own consumer, you have the responsibility to remove the value.- Parameters:
closeTabConsumer
- the consumer called when the close gui control is clicked.
-
setSelectedTabConsumer
Sets the consumer to be notified when the selected tab changes.- Parameters:
selectedTabConsumer
- the consumer to be notified when the selected tab changes
-
isShowingTabList
public boolean isShowingTabList()Returns true if the popup tab list is showing.- Returns:
- true if the popup tab list is showing
-
setShowTabsAlways
public void setShowTabsAlways(boolean b) Sets whether or not tabs should be display when there is only one tab.- Parameters:
b
- true to show one tab; false collapses tab panel when only one tab exists
-
getValueFor
Returns the value of the tab that generated the given mouse event. If the mouse event is not from one of the tabs, then null is returned.- Parameters:
event
- the MouseEvent to get a value for- Returns:
- the value of the tab that generated the mouse event
-
setIgnoreFocus
public void setIgnoreFocus(boolean ignoreFocusLost) -
getTab
-