jlabel icon right alignment and text left alignment [duplicate]
-
01-07-2021 - |
Question
It is possible to create a jlabel with an icon so that the icon is aligned right ( right justified ) and the text is left justified. That means, in same label component i want the text to appear at the very left end of label and the icon at the far right.
Solution
Standard JLabel cannot make a non-static spacing between icon and text, you can only specify iconTextGap in pixels, icon position relative to text and text alignment.
To make what you want you have a few options:
- Use some container with label at left side and icon in a separate label at right side
- Create specific JLabel UI that will paint icon in the way you want
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow