开发者

Overlay swing components selectively?

开发者 https://www.devze.com 2023-02-03 17:51 出处:网络
I just sta开发者_C百科rted learning swing, and couldn\'t find any clear instructions for this: I\'d like to have a JLabel (which contains the background image) and, rendered on top of it, two (or perh

I just sta开发者_C百科rted learning swing, and couldn't find any clear instructions for this: I'd like to have a JLabel (which contains the background image) and, rendered on top of it, two (or perhaps more) JButtons. If I use the layout manager OverlayLayout, the buttons are rendered on top of each other.

What would be the best way to properly render the buttons on top of the label?


  1. Create a JPanel that contains it's own layout manager (e.g. GridLayout)
  2. Set the size of the JPanel (Assuming OverlayLayout does not size intelligently)
  3. Add JButtons to that panel
  4. Add that panel to the JLabel w/bgimage


A simple solution would be to add them to a JLayeredPane. This way you can control what layer each compoenent is added to.


Depends on your exact requirement. See Background Panel for a couple of suggestions.

0

精彩评论

暂无评论...
验证码 换一张
取 消