Skip to content

JRadioButton JToggleButton ButtonGroup

Change the text color of the JRadioButton

RadioButtonTextColor

The text color and icon of the JRadioButton will change depending on the state of the JRadioButton.

Create a JTabbedPane-like component using CardLayout

Section titled “Create a JTabbedPane-like component using CardLayout”
Create a JTabbedPane-like component using CardLayout

CardLayoutTabbedPane

We will create a JTabbedPane-like component by combining CardLayout with JRadioButton and JTableHeader.

Pagination of JTables using RowFilter

TablePagination

This code uses RowFilter, introduced in JDK 6, to split and display rows in a pagination-like manner within a JTable.

Place a JRadioButton inside a JTable cell

RadioButtonsInTableCell

Place multiple JRadioButtons within a JTable cell.

JRadioButton in a JTable cell

RadioButtonCellEditor

Place a JRadioButton in a JTable cell and configure it so that only one can be selected from the entire table.

Create a ToggleButtonBar using JRadioButton

Section titled “Create a ToggleButtonBar using JRadioButton”
Create a ToggleButtonBar using JRadioButton

ToggleButtonBar

Change the icon of the JRadioButton and create a ToggleButtonBar.

Create a breadcrumb trail by layering buttons in FlowLayout

Section titled “Create a breadcrumb trail by layering buttons in FlowLayout”
Create a breadcrumb trail by layering buttons in FlowLayout

BreadcrumbList

By setting the horizontal spacing of the FlowLayout to a negative value and displaying JRadioButtons on top of each other, we create a breadcrumb-like component.

Drawing borders on adjacent components using JLayer

Section titled “Drawing borders on adjacent components using JLayer”
Drawing borders on adjacent components using JLayer

OverlapBorderPaintLayer

JLayer is used to draw edges and shadows on adjacent components.

Displaying JToggleButtons overlaid in FlowLayout

Section titled “Displaying JToggleButtons overlaid in FlowLayout”
Displaying JToggleButtons overlaid in FlowLayout

BackgroundButtonIcon

This example uses FlowLayout to overlap non-rectangular JToggleButtons with left-aligned button text by a specified width.

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.

Clicking a selected JToggleButton within a ButtonGroup will allow you to deselect it

Section titled “Clicking a selected JToggleButton within a ButtonGroup will allow you to deselect it”
Clicking a selected JToggleButton within a ButtonGroup will allow you to deselect it

ToggleButtonGroup

This sets up a JToggleButton within a ButtonGroup so that clicking the selected JToggleButton again will deselect it.

Check if a button in the ButtonGroup is selected

Section titled “Check if a button in the ButtonGroup is selected”
Check if a button in the ButtonGroup is selected

ButtonGroupEmptySelection

This checks if any buttons within the ButtonGroup are selected.

Open a pop-up menu from JToggleButton

ToolButtonPopup

Create a JToggleButton that displays a pop-up menu when clicked, and add it to the toolbar.

Clear selections such as JRodioButton within ButtonGroup

Section titled “Clear selections such as JRodioButton within ButtonGroup”
Clear selections such as JRodioButton within ButtonGroup

ClearGroupSelection

This code uses a feature added in JDK6 to clear the selection within a ButtonGroup.

Change the default icon of the JRadioButton to a thumbnail

Section titled “Change the default icon of the JRadioButton to a thumbnail”
Change the default icon of the JRadioButton to a thumbnail

RadioButtonSelectedBorder

This modifies the default radio buttons in JRadioButton to image thumbnails, and the selected state button to an icon with an outline drawn over the thumbnail.

Place a scroll lock button below the JScrollBar

Section titled “Place a scroll lock button below the JScrollBar”
Place a scroll lock button below the JScrollBar

ScrollLockCornerButton

Place the vertical JScrollBars obtained from the JScrollPane and the JToggleButtons to lock their scrolling into a separate panel.

Place a vertical JSlider in JPopupMenu and display it above the JToggleButton

Section titled “Place a vertical JSlider in JPopupMenu and display it above the JToggleButton”
Place a vertical JSlider in JPopupMenu and display it above the JToggleButton

PopupVolumeSlider

A vertical JSlider is placed in the JPopupMenu, and when the JToolTip set in the JToggleButton is displayed, it is overlaid on top of it.

Create a ButtonGroup or JComboBox for selecting an Enum constant using JRodioButton

Section titled “Create a ButtonGroup or JComboBox for selecting an Enum constant using JRodioButton”
Create a ButtonGroup or JComboBox for selecting an Enum constant using JRodioButton

EnumInputSelect

This process creates selection components such as JRadioButton's ButtonGroup, JComboBox, and JSpinner from a list of enum constants and retrieves the specified enum constant.

Position the JRadioButton so that its text starting position aligns with the vertically aligned JLabel

Section titled “Position the JRadioButton so that its text starting position aligns with the vertically aligned JLabel”
Position the JRadioButton so that its text starting position aligns with the vertically aligned JLabel

RadioButtonsLabelAlignment

The text of JRadioButtons and JCheckBoxes, excluding the selection icons, will be aligned with the text of vertically positioned JLabels.

Change the background color of the checkbox and JRadioButton check icons

Section titled “Change the background color of the checkbox and JRadioButton check icons”
Change the background color of the checkbox and JRadioButton check icons

CheckIconInteriorBackground

This modifies the interior background color used for drawing the check icon of JCheckBox and JRadioButton.

Draw a JRadioButton inside a JToggleButton, synchronized with its selection state

Section titled “Draw a JRadioButton inside a JToggleButton, synchronized with its selection state”
Draw a JRadioButton inside a JToggleButton, synchronized with its selection state

RadioCard

A RadioCard is created by drawing a JRadioButton with synchronized selection states and multi-line text within a JTobbleButton.

Display a check icon when the JToggleButton is selected

Section titled “Display a check icon when the JToggleButton is selected”
Display a check icon when the JToggleButton is selected

CheckButtonToggleGroup

When the JToggleButton is selected, a check icon is displayed; when it is not selected, an icon with a size of 0 is set and it is hidden.

Set a rotation animation expand/collapse icon for JToggleButton

Section titled “Set a rotation animation expand/collapse icon for JToggleButton”
Set a rotation animation expand/collapse icon for JToggleButton

RotatingAnimationToggleIcon

This JToggleButton sets up an expand/collapse icon that rotates 90 degrees clockwise with animation when selected, and rotates -90 degrees back to its original 0 degrees when deselected.

Create a dot indicator with JToggleButton

DotNavigationSlideshow

Create a dot indicator with JToggleButton and place it at the bottom of the page, and perform a screen transition with a scroll animation when the mouse is clicked, etc.