Skip to content

JLabel

Displaying multiple lines using JTextPane, JLabel, etc

Section titled “Displaying multiple lines using JTextPane, JLabel, etc”
Displaying multiple lines using JTextPane, JLabel, etc

MultiLineLabel

This example tests multi-line labels using JTextPane, JTextArea, and JLabel.

Disabling JLabel and JEditorPane using HTML

Section titled “Disabling JLabel and JEditorPane using HTML”
Disabling JLabel and JEditorPane using HTML

DisabledHtmlLabel

This tests how the display looks when JLabel and JEditorPane using HTML are disabled.

Section titled “Displaying hyperlinks using JLabel, JButton, and JEditorPane”
Displaying hyperlinks using JLabel, JButton, and JEditorPane

HyperlinkLabel

This code displays a hyperlink using a JLabel, JButton, and JEditorPane, and captures the event that occurs when each is clicked.

Change the icon’s color tone with RGBImageFilter

Section titled “Change the icon’s color tone with RGBImageFilter”
Change the icon's color tone with RGBImageFilter

RatingLabel

Prepare icons with modified color tones using RGBImageFilter, and then create a component for evaluation.

JLabel text alignment

JustifiedLabel

This test uses JLabel to determine text alignment options such as left, right, center, and both ends.

Wrap the string in a JLabel

GlyphVector

We'll use GlyphVector to wrap and display the label text.

Make the JLabel's text blink

BlinkLabel

We will create a JLabel that blinks a string using javax.swing.Timer.

Disable HTML rendering for JLabels and other elements

Section titled “Disable HTML rendering for JLabels and other elements”
Disable HTML rendering for JLabels and other elements

HtmlDisable

This disables HTML rendering for JLabels and other elements, displaying tag strings directly.

Change the shape of the JComponent

MoveNonRectangularImage

This modifies the area of ​​the component that responds to the mouse cursor to match the opaque area of ​​the image icon set in the JLabel.

JLabel icon and text position

TextPositionAndAlignment

This tests the position of the JLabel icon and text.

JTabbedPane tab icon and title position

TabTitleTextPosition

This modifies the position of the title and icon within the JTabbedPane tab.

Clipping HTML-modified strings

ClippedHtmlLabel

Modifying a string in HTML prevents it from being clipped, so create a clipped string beforehand before using HTML.

Register and use the font in GraphicsEnvironment

Section titled “Register and use the font in GraphicsEnvironment”
Register and use the font in GraphicsEnvironment

RegisterFont

This registers the font in GraphicsEnvironment so that it can be used in HTML tags and other elements.

Get the font outline and modify the inside of the string

Section titled “Get the font outline and modify the inside of the string”
Get the font outline and modify the inside of the string

LineSplittingLabel

By setting a clip, you can limit the drawing area and decorate the inside of the text with a different color.

Display drag icons even outside of JFrame

DragSourceMotionListener

By obtaining the cursor position during dragging using DragSourceMotionListener and moving the window containing the added icon to that position, the drag icon can be displayed even outside of the JFrame.

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.

Stop the animation of the AnimatedGIF displayed in the JLabel

Section titled “Stop the animation of the AnimatedGIF displayed in the JLabel”
Stop the animation of the AnimatedGIF displayed in the JLabel

DisableAnimatedGif

This stops the animation of the AnimatedGIF displayed in the JLabel.

Drag and rearrange the icons placed in the JToolBar

Section titled “Drag and rearrange the icons placed in the JToolBar”
Drag and rearrange the icons placed in the JToolBar

RearrangeToolBarIcon

You can rearrange the icons placed in the JToolBar by dragging and dropping them.

Perform initial grouping with JLabel

DropcapLabel

The first character of the JLabel is enlarged, the remaining text is arranged in a TextLayout to wrap around it, and then drawn using a drop cap.

The search location display bar created with JLabel and Icon can be operated with the mouse

Section titled “The search location display bar created with JLabel and Icon can be operated with the mouse”
The search location display bar created with JLabel and Icon can be operated with the mouse

BoundedRangeModel

We obtain the BoundedRangeModel from the JScrollBar and make the search position display bar, which is shown using a JLabel and Icon, operable with the mouse.

Setting the alignment when displaying multi-line HTML text in a TableCellRenderer

Section titled “Setting the alignment when displaying multi-line HTML text in a TableCellRenderer”
Setting the alignment when displaying multi-line HTML text in a TableCellRenderer

HtmlCellVerticalAlignment

This test examines how line alignment affects rendering when displaying multi-line HTML text in a JTable cell.

Change the text color of HTML anchor tags displayed in JLabel

Section titled “Change the text color of HTML anchor tags displayed in JLabel”
Change the text color of HTML anchor tags displayed in JLabel

AnchorTextColor

This will test changing the default text color of HTML anchor tags displayed in JLabel and JEditorPane.

Align text within JTable cells to both ends

Section titled “Align text within JTable cells to both ends”
Align text within JTable cells to both ends

InterIdeographJustify

This sets the text placed within a JTable cell to justify its alignment.

Display a checkbox generated using HTML formatted input tags in a JLabel

Section titled “Display a checkbox generated using HTML formatted input tags in a JLabel”
Display a checkbox generated using HTML formatted input tags in a JLabel

InputTypeCheckBox

A checkbox generated using an HTML-formatted input tag is displayed in the TableCellRenderer of the header, which inherits from JLabel, and its state changes when clicked.

Generate a color from HTML hexadecimal color codes

Section titled “Generate a color from HTML hexadecimal color codes”
Generate a color from HTML hexadecimal color codes

HTMLColorCodes

This tests how to generate a Color from an HTML hexadecimal color code and change the text color of a JLabel.

Applying condensation to the font for use in JTextArea

Section titled “Applying condensation to the font for use in JTextArea”
Applying condensation to the font for use in JTextArea

CondensedFontLabel

This generates a font with characters stretched condensed, and then uses it in components such as JTextArea.

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.

Share the maximum width of JLabels to align vertical positions across different panels

Section titled “Share the maximum width of JLabels to align vertical positions across different panels”
Share the maximum width of JLabels to align vertical positions across different panels

AlignedLabel

To align the vertical position of JLabels across different panels, we search for the widest JLabel and use this as the recommended size for all of them.

Change the text overflow effect in a JLabel to a fade-out effect

Section titled “Change the text overflow effect in a JLabel to a fade-out effect”
Change the text overflow effect in a JLabel to a fade-out effect

TextOverflowFadeLabel

When text overflows in JLabels or similar elements, instead of using the default ellipsis, a fade-out effect is applied to make the characters near the edges transparent.

Change the tab string overflow effect in JTabbedPane to a fade-out effect

Section titled “Change the tab string overflow effect in JTabbedPane to a fade-out effect”
Change the tab string overflow effect in JTabbedPane to a fade-out effect

TextOverflowFadeTabbedPane

If the tab string in JTabbedPane overflows, instead of truncating it with the ... symbol, the characters near the edges will be made transparent with a fade-out effect.

Investigating whether the mouse cursor is on the JLabel icon or the text

Section titled “Investigating whether the mouse cursor is on the JLabel icon or the text”
Investigating whether the mouse cursor is on the JLabel icon or the text

LayoutCompoundLabel

This changes the tooltip content depending on whether the mouse cursor is over the JLabel icon or the text.

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.

Displaying a badge on an icon within a JLabel using JLayer

Section titled “Displaying a badge on an icon within a JLabel using JLayer”
Displaying a badge on an icon within a JLabel using JLayer

NotificationBadge

A badge is displayed on top of the icon set in the JLabel using a JLayer.

Convert the dates in the calendar created with JTable into numbers

Section titled “Convert the dates in the calendar created with JTable into numbers”
Convert the dates in the calendar created with JTable into numbers

ColorUniversalDesignCalendar

If a date in the calendar created with JTable is a holiday, it will be changed to a number enclosed in a JLabel.

Display diagonally rotated text and a ribbon overlaid in the corner of the JLabel

Section titled “Display diagonally rotated text and a ribbon overlaid in the corner of the JLabel”
Display diagonally rotated text and a ribbon overlaid in the corner of the JLabel

CornerRibbonLabel

The text will be displayed in the upper right corner of the JLabel, rotated 45 degrees, and overlaid with the ribbon.

Set tracking for the font to reduce the string width before rendering

Section titled “Set tracking for the font to reduce the string width before rendering”
Set tracking for the font to reduce the string width before rendering

Tracking

The font is rendered with a reduced width by setting a negative tracking value.

Display the icon by rotating it in quarter-circle increments

Section titled “Display the icon by rotating it in quarter-circle increments”
Display the icon by rotating it in quarter-circle increments

QuadrantRotateIcon

Rotate the icons by 90 degrees each and place them in the JLabel.

Make the text color of the JLabel semi-transparent

Section titled “Make the text color of the JLabel semi-transparent”
Make the text color of the JLabel semi-transparent

TranslucentLabelForeground

This tests how to set the text and background colors of a JLabel to semi-transparent.

Display a background image using a JLabel text tag

Section titled “Display a background image using a JLabel text tag”
Display a background image using a JLabel text tag

KnockoutTextLabel

This displays a background image drawn on a JLabel as if it were cut out using a text shape.

Rotate and display the Animated GIF

RotateAnimatedGifImageIcon

This tests a method for rotating and displaying an ImageIcon generated from an AnimatedGIF.

Get the string boundaries from the font

StringBounds

This tests how to generate TextLayout and GlyphVector from a Font and obtain the width and height of a string.

Round the corners of the JTableHeader

RoundedCornerTableHeader

We create a calendar by setting a TableCellRenderer to round the corners of the JTableHeader and changing its background color according to the month.

Get the color of the clicked position in the image displayed on the JLabel

Section titled “Get the color of the clicked position in the image displayed on the JLabel”
Get the color of the clicked position in the image displayed on the JLabel

ColorPicker

This code displays an image as an icon in a JLabel and retrieves the color of the image at the position where the mouse clicks.

The results of the 5-point rating scale created with GlyphVector are plotted as labels

Section titled “The results of the 5-point rating scale created with GlyphVector are plotted as labels”
The results of the 5-point rating scale created with GlyphVector are plotted as labels

FiveStarRatingLabel

Using GlyphVector, we create an outline of a 5-star rating and then fill in the inside of the rating value to one decimal place.

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.

Round the corners of the title background and border of the TitledBorder

Section titled “Round the corners of the title background and border of the TitledBorder”
Round the corners of the title background and border of the TitledBorder

RoundedTitledBorder

The title background of the TitledBorder is filled with a rounded rectangle with the bottom right corner rounded, and the border is also drawn with rounded rectangles with rounded corners on all four sides.

Create a tag input component that can be added with a JTextField, displayed with a JLabel, and deleted with a JButton

Section titled “Create a tag input component that can be added with a JTextField, displayed with a JLabel, and deleted with a JButton”
Create a tag input component that can be added with a JTextField, displayed with a JLabel, and deleted with a JButton

TagInputPanel

Create a tag input component that uses a JTextField to add tags, displays them with JLabels, and allows them to be deleted using JButtons.

Create a range selection slider with JSliders positioned vertically

Section titled “Create a range selection slider with JSliders positioned vertically”
Create a range selection slider with JSliders positioned vertically

RangeSlider

We create a range selection slider by placing JSliders above and below the selection range and the JLabel for displaying the tick marks, using them as adjustment knobs.

Apply a shimmer effect to the text in a JLabel

Section titled “Apply a shimmer effect to the text in a JLabel”
Apply a shimmer effect to the text in a JLabel

ShimmerLabel

Draw the text in a JLabel using a LinearGradientPaint with an animation that creates a moving glow.