Skip to content
Advertisement

Is there a way to make multiline JLabel text flow around the icon?

Currently in my project I have multiple JLabels each with their own text and icon

The problem I have is that the icon take a whole left side to it self

The effect I’m trying to achieve is to make the text flow around the icon

enter image description here

Is this effect possible with JLabel? if not, is it possible with any other component?

Advertisement

Answer

If this is a JLabel and not a JTextArea where the text is editable I would go with an HTMLed JLabel instead of a JEditorPane.

JavaScript

Run the above example. You will get as result the following image:

enter image description here

The image conversions depends on how you have the icons but the idea is this. Write the image into a temp file, make it an URI and add it as HTML text to the label.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement