How to right-justify icon in a JLabel?
For a JLabel with icon, if you setHorizontalTextPosition(SwingConstants.LEADING) , the icon is painted right after text, no matter how wide the label is. This is particularly bad for a list, as the icons would be all over the place depending on how long the text is for each item. I traced the code and it seems to be that in SwingUtilities#layoutCompoundLabelImpl , text width is simply set to SwingUtilities2.stringWidth(c, fm, text) , and icon x is set to follow text without considering label width. Here is the simplest case: import java.awt.*; import javax.swing.*; public class TestJLabelIcon