Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteSome links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
To change a Swing JLabel’s font size while keeping its current font family and style, call setFont with a derived font:
label.setFont(label.getFont().deriveFont(24f));
The 24f is a size in points, not a promise of 24-pixel-tall text. If you want to set a specific family and style instead, create a java.awt.Font and pass it to setFont.
Complete runnable example
This example creates the Swing interface on the event-dispatch thread, enlarges the label while preserving its current font family and style, and uses pack() so the window fits the label’s preferred size.
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
public class JLabelFontExample {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JLabel label = new JLabel("Large JLabel text", SwingConstants.CENTER);
label.setFont(label.getFont().deriveFont(28f));
JFrame frame = new JFrame("JLabel Font Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(label);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
}
}
Swing components should generally be created and updated on the event-dispatch thread. See Oracle’s Swing threading guidance.
Set a particular font family or style
Use the Font constructor when you want to specify the family and style as well as the size:
import java.awt.Font;
label.setFont(new Font("SansSerif", Font.PLAIN, 20));
The constructor is new Font(family, style, sizeInPoints). Common styles are Font.PLAIN, Font.BOLD, and Font.ITALIC. Combine bold and italic with the bitwise OR operator:
label.setFont(new Font("SansSerif", Font.BOLD | Font.ITALIC, 24));
SansSerif, Serif, and Monospaced are logical font names, useful when you want Java to select a suitable available font across systems. A specific family such as Arial or Segoe UI may not be installed everywhere; Java can substitute another font. The Font API documents constructors, styles, and font derivation.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Change only the size, or change size and style
deriveFont(float) creates a font based on the existing one, retaining its family and style while changing the point size. This is usually the right choice when you only want to enlarge or shrink a label and preserve the look-and-feel’s font:
label.setFont(label.getFont().deriveFont(18f));
To preserve the current family but set both the style and size, use the overload that accepts a style and size:
label.setFont(label.getFont().deriveFont(Font.BOLD, 24f));
JLabel inherits setFont and getFont through Swing’s component hierarchy; see the JLabel API and Component font methods.
Changing the font after the window opens
If the label is already displayed, update its font and ask its container to lay out and repaint the component:
Free tools Windows power users keep installed
One-click scans. No signup required.
label.setFont(label.getFont().deriveFont(32f));
label.revalidate();
label.repaint();
If you also want the containing frame to resize around the new preferred size, call pack() on the frame:
frame.pack();
pack() resizes the window, so use it only when that is desired. revalidate() and repainting request layout and visual updates; Window.pack() sizes a window to fit its components’ preferred sizes.
Make room for larger text
Changing the font changes the label’s preferred dimensions. With a suitable layout manager, the parent can use those updated dimensions to lay out its children. If text is clipped, check whether you have assigned fixed bounds such as setBounds(10, 10, 100, 20), or whether a parent panel, dialog, or scroll area constrains the label. Remove unnecessary fixed sizing and use a layout manager where possible; see Oracle’s Swing layout-manager guide.
For a one-time change before showing the window, set the font before calling pack(). For a later change, call revalidate() and repaint(), and optionally repack the frame if you want it to resize. Larger text can also make dialogs or aligned rows wider or taller, so check the surrounding interface at the display scaling settings your application supports.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Set a default font for labels
If an application has a consistent typography policy, you can set the Swing UI default for labels before creating them:
Rank #4
import java.awt.Font;
import javax.swing.UIManager;
UIManager.put("Label.font", new Font(Font.SANS_SERIF, Font.PLAIN, 18));
JLabel first = new JLabel("First");
JLabel second = new JLabel("Second");
This configures a default; it is different from explicitly setting the font on one label and should not be treated as a guarantee that every already-created label will change. A practical order is to select the look and feel, apply application-specific defaults, then build the UI. If you change the look and feel after creating components, update the component tree with SwingUtilities.updateComponentTreeUI(frame) and reapply component-specific fonts if needed. See the UIManager documentation.
To change labels that already exist, set their fonts individually. For example, if you have a list of labels:
for (JLabel label : labels) {
label.setFont(label.getFont().deriveFont(18f));
}
For labels nested in a container hierarchy, you can visit components recursively:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →import java.awt.Component;
import java.awt.Container;
import javax.swing.JLabel;
static void setLabelFontSize(Container container, float size) {
for (Component component : container.getComponents()) {
if (component instanceof JLabel label) {
label.setFont(label.getFont().deriveFont(size));
}
if (component instanceof Container child) {
setLabelFontSize(child, size);
}
}
}
This changes existing JLabel instances; it does not set a default for labels created later. The example’s pattern-matching instanceof syntax requires a modern Java version that supports it. On older Java versions, use a traditional cast after the instanceof check.
Best Value
Use different sizes within one label
A regular JLabel has one component font. For simple mixed formatting, a label can render basic HTML:
JLabel label = new JLabel(
"<html><span style='font-size:24pt'>Title</span> "
+ "<span style='font-size:12pt'>subtitle</span></html>"
);
Swing’s HTML rendering is limited and is not equivalent to a browser’s full CSS support. For complex rich text or more control, consider a JTextPane instead. See Oracle’s guide to HTML in Swing components.
Custom fonts
If you need a particular font that may not be installed on the target system, you can bundle a licensed font file with the application and load it from the classpath. For a TrueType font:
import java.awt.Font;
import java.io.InputStream;
try (InputStream in = MyClass.class.getResourceAsStream("/fonts/MyFont.ttf")) {
if (in == null) {
throw new IllegalStateException("Font resource not found");
}
Font baseFont = Font.createFont(Font.TRUETYPE_FONT, in);
label.setFont(baseFont.deriveFont(24f));
}
The resource path must be packaged with the application, and the font’s licence must allow redistribution. If needed, the font can be registered with the graphics environment using GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(baseFont). Consult the GraphicsEnvironment API.
Troubleshooting
- The text is cut off: Check fixed bounds and parent constraints. Revalidate and repaint after a runtime change; call
pack()if the window should resize. - The family looks unchanged: The requested font may not be installed, and Java may have substituted another. Use a logical font for portability or bundle an appropriately licensed font.
setFontseems to do nothing: Confirm you are modifying the same label that is displayed, that later code does not replace or reset it, and that HTML markup is not controlling the text’s appearance.- A UI default has no effect on existing labels:
UIManager.putconfigures defaults; it is not the same as callingsetFonton every existing component. - A GUI builder resets the change: Use the designer’s font property when available. Generated initialization code may be regenerated and overwrite manual edits.
To check the font currently assigned to a label, inspect it directly:
Font font = label.getFont();
System.out.println(font.getFamily());
System.out.println(font.getStyle());
System.out.println(font.getSize());
This article covers Swing’s javax.swing.JLabel. JavaFX has a different Label class and styling API; do not use JavaFX font code on a Swing label.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

