Search code examples
javaswingjbuttonjlabelnull-layout-manager

How do I make a JLabel always stay above a JButton?


So I have a gui where the layout is set to Null, and I put JLabels ontop of JButtons since the JButtons have icons and adding text to the button makes the button look distorted, so instead I am using JLabels ontop of the JButtons. Every time the mouse goes over the JButton when I test it, the JLabel disappears. How can I fix that so JLabels always appear above JButtons.

Edit: it distorts the button so the icon is taking up most the space and the button label is cut off by the opposite edge of the button.


Solution

  • If you're using a JFrame, as I assume you must be, you could add the labels to a JLayered pane that sits on top of the content pane.