Having a JLabel on top of another JLabel that has an image(在另一个具有图像的 JLabel 之上有一个 JLabel)
问题描述
Soo I'm trying to make a board game with GUI. I created a JLabel with the player's name and want to use that as a token. Then I made another JLabel that contains the image of the board. I added both the labels onto a boardPanel and right now, the labels are side by side. How do I make it so that instead of it being side to side, the JLabel w/ name is on the JLabel w/ img?
Is there something I should be considering for the panel that contains the two labels? Like a certain Layout Manager?
[just sections of my code]
something like this but obviously instead of a cat, it's the board image, and the text is the player name.
EDIT
I made a class that extends the jpanel and then wanted to add it into the BoardFrame class
Board Frame class:
Player Steven still does not seem to appear on the map.
You could make use of an OverlayLayout
or you could simply add the second JLabel
to the first. The trick here though, is to set up a layout manager for the first label.
Beware though, a JLabel
only use the icon
and text
properties its determine the preferred layout size, which could end up truncating it's children
这篇关于在另一个具有图像的 JLabel 之上有一个 JLabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!