Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 502171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:15:52+00:00 2026-05-13T06:15:52+00:00

Is there a widget for Swing that behaves like a JLabel , that automatically

  • 0

Is there a widget for Swing that behaves like a JLabel, that automatically reflows the text if its dimensions have changed? For example:

Large horizontal space available:
+--------------+
| Foo bar baz  |
+--------------+

Small horizontal space available:
+---------+
| Foo bar |
| baz     |
+---------+

I am currently using JEditorPane with setContentType("text/html") and HTML content. This works, but it does not use the System’s default label font for displaying the text. Also, I would rather not put HTML tags into my text – at best, \n characters would be transformed into line breaks and everything else would be displayed as text.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:15:53+00:00Added an answer on May 13, 2026 at 6:15 am

    I have made a custom UI delegate for JLabel to support multiple lines. It will wrap your text to fit the available space and also respect hard line breaks. The wrapped text should reflow when the component size changes. The UI delegate listens for changes to the component’s dimension and recalculates the line breaks automatically.

    Using the UI delegate is as straight forward as:

    JLabel label = new JLabel("Text that'll wrap if necessary");
    label.setUI(MultiLineLabelUI.labelUI);

    Or alternatively use the custom MultiLineLabel class that in addition to wrapping text supports vertical and horizontal text alignment.

    Here’s the project: https://github.com/sasjo/multiline

    If you compile and try the demo, it should reflow fine on OS X. If I remember correctly there’s some problem with reflowing upon resizing the frame on Windows. Didn’t look in to it at the time, but it seemed that the resized event never propagated to the label.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering if there is a widget that acts like a ScrollPane in
I would very much like to know if there is a widget that exists
Is there an existing library that automatically creates a Java Swing form from a
Is there any open source similar to Facebook's share/status update widget or I have
Does anyone know of a GWT widget that works like a spelling suggestor? Ideally
Is there any android widget that enable to pick the date and the time
I am looking for an SWT widget that would have the look and behavior
Is there a widget to embed an explorer-like view inside an ms access form?
Is there a widget for rendering a foreign key field in Django admin that
Is there any widget like EditText which contains a cross button, or is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.