Package com.formdev.flatlaf.ui
Class FlatTitlePane
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- com.formdev.flatlaf.ui.FlatTitlePane
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable
public class FlatTitlePane extends javax.swing.JComponentProvides the Flat LaF title bar.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classFlatTitlePane.FlatTitleLabelUIprotected classFlatTitlePane.FlatTitlePaneBorderprotected classFlatTitlePane.Handlerstatic interfaceFlatTitlePane.TitleBarCaptionHitTestFor custom components useFlatClientProperties.COMPONENT_TITLE_BAR_CAPTIONinstead of this interface.-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.ColoractiveBackgroundprotected java.awt.ColoractiveForegroundprotected java.awt.ColorborderColorprotected intbuttonMaximizedHeightprotected intbuttonMinimumWidthprotected javax.swing.JPanelbuttonPanelprotected booleanbuttonsFillVerticallyprotected intbuttonsGapprotected java.awt.InsetsbuttonsMarginsprotected booleancenterTitleprotected booleancenterTitleIfMenuBarEmbeddedprotected javax.swing.JButtoncloseButtonprivate java.awt.RectangledebugAppIconBoundsprivate java.awt.RectangledebugCloseButtonBoundsprivate java.awt.RectangledebugMaximizeButtonBoundsprivate java.awt.RectangledebugMinimizeButtonBoundsprivate intdebugTitleBarHeightprotected java.awt.ColorembeddedForegroundprivate FlatTitlePane.Handlerhandlerprotected javax.swing.JButtoniconifyButtonprivate javax.swing.JComponenticonifyMaximizeGapCompprotected javax.swing.JLabeliconLabelprotected java.awt.InsetsiconMarginsprotected java.awt.DimensioniconSizeprotected java.awt.ColorinactiveBackgroundprotected java.awt.ColorinactiveForegroundprivate static booleanisWindows_10(package private) static java.lang.StringKEY_DEBUG_SHOW_RECTANGLESprivate booleanlastCaptionHitTestResultprivate longlastCaptionHitTestTimeprivate intlastCaptionHitTestXprivate intlastCaptionHitTestYprivate intlaterCounterprotected javax.swing.JPanelleftPanelprotected javax.swing.JButtonmaximizeButtonprivate javax.swing.JComponentmaximizeCloseGapCompprotected javax.swing.JComponentmenuBarPlaceholderprotected intmenuBarTitleGapprotected intmenuBarTitleMinimumGap(package private) javax.swing.JPanelmouseLayerThis panel handles mouse events if FlatLaf window decorations are used without native window border.protected intnoIconLeftGapprotected javax.swing.JButtonrestoreButtonprotected javax.swing.JRootPanerootPaneprotected booleanshowIconprotected booleanshowIconBesideTitleprotected booleanshowIconInDialogsprotected java.awt.FonttitleFontprotected javax.swing.JLabeltitleLabelprotected java.awt.InsetstitleMarginsprotected inttitleMinimumWidthprotected java.awt.Windowwindowprotected java.lang.StringwindowStyle(package private) javax.swing.JPanelwindowTopBorderLayerThis panel paint a border at the top of the window in fullWindowContent mode, if FlatLaf window decorations are enabled.-
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
-
-
Constructor Summary
Constructors Constructor Description FlatTitlePane(javax.swing.JRootPane rootPane)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidactiveChanged(boolean active)voidaddNotify()protected voidaddSubComponents()private java.awt.RectangleboundsInWindow(javax.swing.JComponent c)private booleancaptionHitTest(java.awt.Point pt)Returns whether there is a component at the given location, that processes mouse events.protected voidclose()Closes the window.private booleancontains(java.awt.Component c, int x, int y)Same asComponent.contains(int, int), but not using that method because it may be overridden by custom components and invoke code that tries to request AWT tree lock on 'AWT-Windows' thread.protected javax.swing.JButtoncreateButton(java.lang.String iconKey, java.lang.String accessibleName, java.awt.event.ActionListener action)protected voidcreateButtons()private javax.swing.JComponentcreateButtonsGapComp()protected FlatTitlePane.HandlercreateHandler()protected FlatTitlePane.FlatTitlePaneBordercreateTitlePaneBorder()private voiddebugPaintComponentWithMouseListener(java.awt.Graphics g, java.awt.Color color, java.awt.Component c, int x, int y)private voiddebugPaintRect(java.awt.Graphics g, java.awt.Color color, java.awt.Rectangle r)protected java.awt.ComponentfindHorizontalGlue(javax.swing.JMenuBar menuBar)protected voidframeStateChanged()java.awt.ColorgetBackground()protected java.awt.RectanglegetMenuBarBounds()(package private) static java.lang.StringgetWindowStyle(javax.swing.JRootPane rootPane)protected java.lang.StringgetWindowTitle()protected booleanhasNativeCustomDecoration()Returns whether windows uses native window border and has custom decorations enabled.protected booleanhasVisibleEmbeddedMenuBar(javax.swing.JMenuBar menuBar)Returns whether this title pane currently has a visible and embedded menubar.protected voidiconify()Iconifies the window.protected voidinstallWindowListeners()protected booleanisFullWindowContent()private booleanisMaximizedBoundsFixed()Frame.setMaximizedBounds() behaves different on some Java versions after issues https://bugs.openjdk.java.net/browse/JDK-8231564 and https://bugs.openjdk.java.net/browse/JDK-8176359 (see also https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8176359) were fixed in Java 15 and backported to 11.0.8 and 13.0.4.protected booleanisMenuBarEmbedded()Returns whether the menubar should be embedded into the title pane.private booleanisTitleBarCaptionAt(java.awt.Component c, int x, int y)protected booleanisWindowMaximized()(package private) booleanisWindowTopBorderNeeded()protected voidmaximize()Maximizes the window.private voidmaximizeOrRestore()protected voidmenuBarChanged()(package private) voidmenuBarInvalidate()protected voidmenuBarLayouted()voidpaint(java.awt.Graphics g)protected voidpaintComponent(java.awt.Graphics g)voidremoveNotify()protected voidrestore()Restores the window size.protected voidtitleBarColorsChanged()protected voiduninstallWindowListeners()(package private) voidupdateFullWindowContentButtonsBoundsProperty()protected voidupdateIcon()protected voidupdateMaximizedBounds()protected voidupdateNativeTitleBarHeightAndHitTestSpots()protected voidupdateNativeTitleBarHeightAndHitTestSpotsLater()protected voidupdateVisibility()-
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, 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, updateUI
-
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, getAccessibleContext, 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
-
-
-
-
Field Detail
-
KEY_DEBUG_SHOW_RECTANGLES
static final java.lang.String KEY_DEBUG_SHOW_RECTANGLES
- See Also:
- Constant Field Values
-
isWindows_10
private static final boolean isWindows_10
-
titleFont
protected final java.awt.Font titleFont
- Since:
- 2.5
-
activeBackground
protected final java.awt.Color activeBackground
-
inactiveBackground
protected final java.awt.Color inactiveBackground
-
activeForeground
protected final java.awt.Color activeForeground
-
inactiveForeground
protected final java.awt.Color inactiveForeground
-
embeddedForeground
protected final java.awt.Color embeddedForeground
-
borderColor
protected final java.awt.Color borderColor
-
showIcon
protected final boolean showIcon
- Since:
- 2
-
showIconInDialogs
protected final boolean showIconInDialogs
- Since:
- 2.5
-
noIconLeftGap
protected final int noIconLeftGap
- Since:
- 2
-
iconSize
protected final java.awt.Dimension iconSize
-
iconMargins
protected final java.awt.Insets iconMargins
- Since:
- 3.6
-
titleMargins
protected final java.awt.Insets titleMargins
- Since:
- 3.6
-
titleMinimumWidth
protected final int titleMinimumWidth
- Since:
- 2.4
-
buttonMinimumWidth
protected final int buttonMinimumWidth
- Since:
- 2.4
-
buttonMaximizedHeight
protected final int buttonMaximizedHeight
-
buttonsGap
protected final int buttonsGap
- Since:
- 3.6
-
buttonsMargins
protected final java.awt.Insets buttonsMargins
- Since:
- 3.6
-
buttonsFillVertically
protected final boolean buttonsFillVertically
- Since:
- 3.6
-
centerTitle
protected final boolean centerTitle
-
centerTitleIfMenuBarEmbedded
protected final boolean centerTitleIfMenuBarEmbedded
-
showIconBesideTitle
protected final boolean showIconBesideTitle
- Since:
- 2.4
-
menuBarTitleGap
protected final int menuBarTitleGap
-
menuBarTitleMinimumGap
protected final int menuBarTitleMinimumGap
- Since:
- 2.4
-
rootPane
protected final javax.swing.JRootPane rootPane
-
windowStyle
protected final java.lang.String windowStyle
-
leftPanel
protected javax.swing.JPanel leftPanel
-
iconLabel
protected javax.swing.JLabel iconLabel
-
menuBarPlaceholder
protected javax.swing.JComponent menuBarPlaceholder
-
titleLabel
protected javax.swing.JLabel titleLabel
-
buttonPanel
protected javax.swing.JPanel buttonPanel
-
iconifyButton
protected javax.swing.JButton iconifyButton
-
maximizeButton
protected javax.swing.JButton maximizeButton
-
restoreButton
protected javax.swing.JButton restoreButton
-
closeButton
protected javax.swing.JButton closeButton
-
iconifyMaximizeGapComp
private javax.swing.JComponent iconifyMaximizeGapComp
-
maximizeCloseGapComp
private javax.swing.JComponent maximizeCloseGapComp
-
window
protected java.awt.Window window
-
handler
private final FlatTitlePane.Handler handler
-
mouseLayer
final javax.swing.JPanel mouseLayer
This panel handles mouse events if FlatLaf window decorations are used without native window border. E.g. on Linux.This panel usually has same bounds as the title pane, except if fullWindowContent mode is enabled.
This panel is not a child of the title pane. Instead it is added by FlatRootPaneUI to the layered pane at a layer under the title pane and under the frame content. The separation is necessary for fullWindowContent mode, where the title pane is layered over the frame content (for title pane buttons), but the mousePanel needs to be layered under the frame content so that components on content pane can receive mouse events when located in title area.
-
windowTopBorderLayer
final javax.swing.JPanel windowTopBorderLayer
This panel paint a border at the top of the window in fullWindowContent mode, if FlatLaf window decorations are enabled. Only used on Windows 10.This panel is not a child of the title pane. Instead it is added by FlatRootPaneUI to the layered pane at a layer over all other layers.
-
laterCounter
private int laterCounter
-
lastCaptionHitTestX
private int lastCaptionHitTestX
-
lastCaptionHitTestY
private int lastCaptionHitTestY
-
lastCaptionHitTestTime
private long lastCaptionHitTestTime
-
lastCaptionHitTestResult
private boolean lastCaptionHitTestResult
-
debugTitleBarHeight
private int debugTitleBarHeight
-
debugAppIconBounds
private java.awt.Rectangle debugAppIconBounds
-
debugMinimizeButtonBounds
private java.awt.Rectangle debugMinimizeButtonBounds
-
debugMaximizeButtonBounds
private java.awt.Rectangle debugMaximizeButtonBounds
-
debugCloseButtonBounds
private java.awt.Rectangle debugCloseButtonBounds
-
-
Method Detail
-
getWindowStyle
static java.lang.String getWindowStyle(javax.swing.JRootPane rootPane)
-
createTitlePaneBorder
protected FlatTitlePane.FlatTitlePaneBorder createTitlePaneBorder()
-
createHandler
protected FlatTitlePane.Handler createHandler()
-
addSubComponents
protected void addSubComponents()
-
createButtons
protected void createButtons()
-
createButton
protected javax.swing.JButton createButton(java.lang.String iconKey, java.lang.String accessibleName, java.awt.event.ActionListener action)
-
createButtonsGapComp
private javax.swing.JComponent createButtonsGapComp()
-
activeChanged
protected void activeChanged(boolean active)
-
frameStateChanged
protected void frameStateChanged()
-
updateVisibility
protected void updateVisibility()
- Since:
- 3
-
updateIcon
protected void updateIcon()
-
updateFullWindowContentButtonsBoundsProperty
void updateFullWindowContentButtonsBoundsProperty()
-
addNotify
public void addNotify()
- Overrides:
addNotifyin classjavax.swing.JComponent
-
removeNotify
public void removeNotify()
- Overrides:
removeNotifyin classjavax.swing.JComponent
-
getWindowTitle
protected java.lang.String getWindowTitle()
-
installWindowListeners
protected void installWindowListeners()
-
uninstallWindowListeners
protected void uninstallWindowListeners()
-
isFullWindowContent
protected boolean isFullWindowContent()
- Since:
- 3.4
-
hasVisibleEmbeddedMenuBar
protected boolean hasVisibleEmbeddedMenuBar(javax.swing.JMenuBar menuBar)
Returns whether this title pane currently has a visible and embedded menubar.
-
isMenuBarEmbedded
protected boolean isMenuBarEmbedded()
Returns whether the menubar should be embedded into the title pane.
-
getMenuBarBounds
protected java.awt.Rectangle getMenuBarBounds()
-
findHorizontalGlue
protected java.awt.Component findHorizontalGlue(javax.swing.JMenuBar menuBar)
-
titleBarColorsChanged
protected void titleBarColorsChanged()
-
menuBarChanged
protected void menuBarChanged()
-
menuBarLayouted
protected void menuBarLayouted()
-
menuBarInvalidate
void menuBarInvalidate()
-
paint
public void paint(java.awt.Graphics g)
- Overrides:
paintin classjavax.swing.JComponent
-
debugPaintComponentWithMouseListener
private void debugPaintComponentWithMouseListener(java.awt.Graphics g, java.awt.Color color, java.awt.Component c, int x, int y)
-
debugPaintRect
private void debugPaintRect(java.awt.Graphics g, java.awt.Color color, java.awt.Rectangle r)
-
paintComponent
protected void paintComponent(java.awt.Graphics g)
- Overrides:
paintComponentin classjavax.swing.JComponent
-
getBackground
public java.awt.Color getBackground()
- Overrides:
getBackgroundin classjava.awt.Component
-
iconify
protected void iconify()
Iconifies the window.
-
isWindowMaximized
protected boolean isWindowMaximized()
- Since:
- 2.4
-
maximize
protected void maximize()
Maximizes the window.
-
updateMaximizedBounds
protected void updateMaximizedBounds()
-
isMaximizedBoundsFixed
private boolean isMaximizedBoundsFixed()
Frame.setMaximizedBounds() behaves different on some Java versions after issues https://bugs.openjdk.java.net/browse/JDK-8231564 and https://bugs.openjdk.java.net/browse/JDK-8176359 (see also https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8176359) were fixed in Java 15 and backported to 11.0.8 and 13.0.4.
-
restore
protected void restore()
Restores the window size.
-
maximizeOrRestore
private void maximizeOrRestore()
-
close
protected void close()
Closes the window.
-
hasNativeCustomDecoration
protected boolean hasNativeCustomDecoration()
Returns whether windows uses native window border and has custom decorations enabled.
-
isWindowTopBorderNeeded
boolean isWindowTopBorderNeeded()
-
updateNativeTitleBarHeightAndHitTestSpotsLater
protected void updateNativeTitleBarHeightAndHitTestSpotsLater()
-
updateNativeTitleBarHeightAndHitTestSpots
protected void updateNativeTitleBarHeightAndHitTestSpots()
-
boundsInWindow
private java.awt.Rectangle boundsInWindow(javax.swing.JComponent c)
-
captionHitTest
private boolean captionHitTest(java.awt.Point pt)
Returns whether there is a component at the given location, that processes mouse events. E.g. buttons, menus, etc.Note:
- This method is invoked often when mouse is moved over window title bar area and should therefore return quickly.
- This method is invoked on 'AWT-Windows' thread (not 'AWT-EventQueue' thread) while processing Windows messages. It must not change any component property or layout because this could cause a dead lock.
-
isTitleBarCaptionAt
private boolean isTitleBarCaptionAt(java.awt.Component c, int x, int y)
-
contains
private boolean contains(java.awt.Component c, int x, int y)Same asComponent.contains(int, int), but not using that method because it may be overridden by custom components and invoke code that tries to request AWT tree lock on 'AWT-Windows' thread. This could freeze the application if AWT tree is already locked on 'AWT-EventQueue' thread.
-
-