Skip to content

Focus

Apply focus to the entire row of the JTable

Section titled “Apply focus to the entire row of the JTable”
Apply focus to the entire row of the JTable

LineFocusTable

This displays the focus of a JTable as being on the entire row, rather than just a single cell.

Sets the background color when a JTextField has focus

Section titled “Sets the background color when a JTextField has focus”
Sets the background color when a JTextField has focus

FocusColor

To make it easier to see which JTextField is being edited, the background color of the focused JTextField is changed.

Display when JTextField has no focus and no text

Section titled “Display when JTextField has no focus and no text”
Display when JTextField has no focus and no text

GhostText

If the JTextField does not have focus and the text is empty, its description will be displayed in a light color.

Displaying a watermark image in a JTextField

Section titled “Displaying a watermark image in a JTextField”
Displaying a watermark image in a JTextField

WatermarkInTextField

This sets the JTextField to display a watermark image when the text field is empty and the field does not have focus.

Move focus to the next row in the JTable using the Tab key

Section titled “Move focus to the next row in the JTable using the Tab key”
Move focus to the next row in the JTable using the Tab key

SelectNextRow

This sets the cell focus to move to the next row when the Tab key is pressed.

Specify the focus when a window is opened

DefaultFocus

This specifies the component that will have focus by default when a window such as a JFrame or JDialog is opened.

JOptionPane default focus

OptionPaneDefaultFocus

This adds a component to the JOptionPane that will have focus by default.

Focus movement

FocusTraversal

Use FocusTraversalPolicy to control focus movement using keys like Tab.

Add arrow keys to FocusTraversalKeys to move focus

Section titled “Add arrow keys to FocusTraversalKeys to move focus”
Add arrow keys to FocusTraversalKeys to move focus

FocusTraversalKeys

This setting allows you to move focus using the arrow keys in addition to the default Tab key.

Manipulating JTables from other components

Section titled “Manipulating JTables from other components”
Manipulating JTables from other components

SelectAllButton

Selecting all rows in a JTable or copying selected rows can be done from other components such as JButtons.

Clear GlobalFocus

ClearGlobalFocusOwner

This clears GlobalFocus, returning the system to a state where there are no components with focus.

Make JPanel the root of the focus traversal cycle

Section titled “Make JPanel the root of the focus traversal cycle”
Make JPanel the root of the focus traversal cycle

FocusCycleRoot

Configure JPanel to be the root of the focus traversal cycle.

Move focus using the mnemonic set in the JLabel

Section titled “Move focus using the mnemonic set in the JLabel”
Move focus using the mnemonic set in the JLabel

LabelForDisplayedMnemonic

A mnemonic is set for a JLabel, and focus is moved to the associated JTextField.

Add a JTextField to a non-editable JTextPane

Section titled “Add a JTextField to a non-editable JTextPane”
Add a JTextField to a non-editable JTextPane

TextFieldOnReadOnlyTextPane

This adds a JTextField to a JTextPane that has been made blank and non-editable.

Focus shift when the value of a JTextField with InputVerifier set is invalid

Section titled “Focus shift when the value of a JTextField with InputVerifier set is invalid”
Focus shift when the value of a JTextField with InputVerifier set is invalid

VerifyInputWhenFocusTarget

This tests the focus movement behavior when the value of a JTextField with InputVerifier set is not in the correct format.

Change the border when a JTree node gains focus

Section titled “Change the border when a JTree node gains focus”
Change the border when a JTree node gains focus

DrawsTreeFocus

The border rendering when a JTree node is selected and focuses is changed using UIManager.

Maintaining the display of selected state using the Caret in JTextArea

Section titled “Maintaining the display of selected state using the Caret in JTextArea”
Maintaining the display of selected state using the Caret in JTextArea

CaretSelectionHighlight

Set a Caret for JTextComponents such as JTextArea, so that the selected text is highlighted even when it does not have focus.

Configure the JTable so that the cell editor gains focus when editing a cell begins

Section titled “Configure the JTable so that the cell editor gains focus when editing a cell begins”
Configure the JTable so that the cell editor gains focus when editing a cell begins

SurrendersFocusOnKeystroke

This setting allows you to toggle whether the cell editor gains focus when you start editing a JTable cell.

Change the JRRadioButton that receives focus first within the ButtonGroup

Section titled “Change the JRRadioButton that receives focus first within the ButtonGroup”
Change the JRRadioButton that receives focus first within the ButtonGroup

ButtonGroupFocusTraversalPolicy

This setting ensures that when the focus is moved using the Tab key, the focus will move to the currently selected JRadioButton within the ButtonGroup.

Test the focus navigation of a component with an InputVerifier set

Section titled “Test the focus navigation of a component with an InputVerifier set”
Test the focus navigation of a component with an InputVerifier set

InputVerifierFocusOrder

This tests the validation of input and the order of focus movement events for components with InputVerifier configured.

Set the initial focus when JFileChooser is opened

Section titled “Set the initial focus when JFileChooser is opened”
Set the initial focus when JFileChooser is opened

FileChooserInitialFocus

When opening a JFileChooser that uses NimbusLookAndFeel, the initial focus is set to the JTextField used to display the file name.

Disable automatic focus downcycling in FocusTraversalPolicy

Section titled “Disable automatic focus downcycling in FocusTraversalPolicy”
Disable automatic focus downcycling in FocusTraversalPolicy

ImplicitDownCycleTraversal

In the panel where you set SortingFocusTraversalPolicy, you implicitly configure it so that the focus does not move downcycle.

Use FocusTraversalPolicy to scroll to the component that has gained focus

Section titled “Use FocusTraversalPolicy to scroll to the component that has gained focus”
Use FocusTraversalPolicy to scroll to the component that has gained focus

AutoScrollOnFocus

Use FocusTraversalPolicy to get the component that has focus and scroll until its entirety is visible.

Execute InputVerifier validation when switching tabs in JTabbedPane

Section titled “Execute InputVerifier validation when switching tabs in JTabbedPane”
Execute InputVerifier validation when switching tabs in JTabbedPane

TabbedPaneInputVerifier

When switching tabs in JTabbedPane, the InputVerifier set for the tab component is executed, and if the input is invalid during validation, the tab switch is canceled.

Configure the behavior when focus is lost from a JFormattedTextField

Section titled “Configure the behavior when focus is lost from a JFormattedTextField”
Configure the behavior when focus is lost from a JFormattedTextField

FocusLostBehavior

Set and test the action to be performed when focus is lost from the JFormattedTextField.

Get all JPopupMenus using MenuSelectionManager

Section titled “Get all JPopupMenus using MenuSelectionManager”
Get all JPopupMenus using MenuSelectionManager

GetAllPopupMenus

The MenuSelectionManager retrieves all JPopupMenus, and you can toggle them to hide at any time.

When a JTextArea receives focus, its height will automatically expand

Section titled “When a JTextArea receives focus, its height will automatically expand”
When a JTextArea receives focus, its height will automatically expand

ExpandingTextArea

When a JTextArea receives focus, its height automatically expands; when it loses focus, it shrinks.

Move the focus to the target JTextField before opening JPopupMenu

Section titled “Move the focus to the target JTextField before opening JPopupMenu”
Move the focus to the target JTextField before opening JPopupMenu

FocusBeforePopup

When opening a JPopupMenu set in a JTextField or similar by right-clicking with the mouse, move the focus to it and select all the text.

Hide the FocusBorder of the JSlider

SliderFocusBorder

In a JSlider that uses WindowsLookAndFeel, set the dotted FocusBorder to be hidden.

Change the target of the JComboBox’s FocusBorder from the internal items to the JComboBox itself

Section titled “Change the target of the JComboBox’s FocusBorder from the internal items to the JComboBox itself”
Change the target of the JComboBox's FocusBorder from the internal items to the JComboBox itself

ComboBoxFocusBorder

This method hides the dotted FocusBorder applied to internal items in a JComboBox using WindowsLookAndFeel, and instead displays a solid FocusBorder on the JComboBox itself.

Enable tab key focus movement within the JTable cell editor

Section titled “Enable tab key focus movement within the JTable cell editor”
Enable tab key focus movement within the JTable cell editor

CellEditorFocusCycle

This setting allows you to move focus within the cell editor using the Tab key when a JTable is being edited.

Changing the drawing range of selection highlights in JEditorPane

Section titled “Changing the drawing range of selection highlights in JEditorPane”
Changing the drawing range of selection highlights in JEditorPane

WholeLineHighlightPainter

This modifies the Caret of JEditorPane so that selection highlighting is displayed even on paragraphs containing only line breaks.

Change the inner margin of focus drawing using dotted lines for JButtons and similar elements

Section titled “Change the inner margin of focus drawing using dotted lines for JButtons and similar elements”
Change the inner margin of focus drawing using dotted lines for JButtons and similar elements

FocusDashedRectGap

This modifies the inner margin of the focus rectangle drawn by a dotted line in a JButton that uses WindowsLookAndFeel or similar effects.

Set DefaultButton to the JButton that has focus

Section titled “Set DefaultButton to the JButton that has focus”
Set DefaultButton to the JButton that has focus

DefaultButtonFollowsFocus

This setting configures a JButton that is not the DefaultButton to behave as the DefaultButton when it has focus.

When a JLabel is clicked, focus is moved to the component assigned to it

Section titled “When a JLabel is clicked, focus is moved to the component assigned to it”
When a JLabel is clicked, focus is moved to the component assigned to it

LabelForRequestFocus

When the JLabel is clicked with the mouse, the focus is moved to the component assigned to this label.

When the JTextField gains focus, the top right and left edges of the border are drawn sequentially

Section titled “When the JTextField gains focus, the top right and left edges of the border are drawn sequentially”
When the JTextField gains focus, the top right and left edges of the border are drawn sequentially

FocusBorderAnimation

When a JTextField gains keyboard focus, it starts a border animation that draws straight lines along its top right and left edges in sequence.

Place focusable components within the JWindow

Section titled “Place focusable components within the JWindow”
Place focusable components within the JWindow

JWindowFocus

We will run tests that place focusable components in JWindow, plain JFrame, JPopupMenu, etc.

Move focus to the tab component that has become visible through tab selection in JTabbedPane

Section titled “Move focus to the tab component that has become visible through tab selection in JTabbedPane”
Move focus to the tab component that has become visible through tab selection in JTabbedPane

RequestFocusForVisibleComponent

This setting ensures that when a JTabbedPane tab is selected with a left mouse press, the focus moves to the visible tab component.

Change the text selection highlight color depending on whether the JFrame is active

Section titled “Change the text selection highlight color depending on whether the JFrame is active”
Change the text selection highlight color depending on whether the JFrame is active

ActiveWindowSelectionHighlight

This code changes the background color of the text selection highlight in its child JTextComponent depending on whether the JFrame is active.

Change the focus border of a JTabbedPane tab to an underline when a tab is selected

Section titled “Change the focus border of a JTabbedPane tab to an underline when a tab is selected”
Change the focus border of a JTabbedPane tab to an underline when a tab is selected

UnderlineTabFocusIndicator

This changes the focus border of a JTabbedPane tab when it is selected from a dotted border to an underline.

Display the focus border of the previously selected tab in JTabbedPane as a history

Section titled “Display the focus border of the previously selected tab in JTabbedPane as a history”
Display the focus border of the previously selected tab in JTabbedPane as a history

PreviouslySelectedTabColor

This changes the focus border color of the currently selected tab and the tab that was selected immediately before it in JTabbedPane.

If the focus movement to the JComboBox is rejected by InputVerifier validation, cancel the display of the dropdown list

Section titled “If the focus movement to the JComboBox is rejected by InputVerifier validation, cancel the display of the dropdown list”
If the focus movement to the JComboBox is rejected by InputVerifier validation, cancel the display of the dropdown list

DisableComboPopupByVerifier

If a mouse click to a JComboBox is rejected by an InputVerifier set in another component, the display of that dropdown list will be canceled.

Separate the selection tab and focus tab in JTabbedPane

Section titled “Separate the selection tab and focus tab in JTabbedPane”
Separate the selection tab and focus tab in JTabbedPane

TabbedPaneSelectionFollowsFocus

This setting allows you to switch between matching the selected tab and the focused tab when switching tabs using keyboard input in JTabbedPane, or treating them separately.

Set a border for a JTextField that changes its border color depending on whether it has focus or not

Section titled “Set a border for a JTextField that changes its border color depending on whether it has focus or not”
Set a border for a JTextField that changes its border color depending on whether it has focus or not

FocusBorder

This sets a border that changes the color of the border around the JTextField and highlights it when it receives focus.

Sets the component’s focus to the order in which it was added to the Container

Section titled “Sets the component’s focus to the order in which it was added to the Container”
Sets the component's focus to the order in which it was added to the Container

ContainerOrderFocusTraversalPolicy

This sets a ContainerOrderFocusTraversalPolicy that cycles the focus movement of components according to the order in which they were added to the parent Container.