Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

java - Why to add JPanel to a JLabel, under what circumstance, this situation can arise?

Today while surfing through various questions, I encountered one QUESTION, this seems to me a bit weird, why would one wants to add a JPanel to a JLabel, are there any genuine reasons as to such situation can arise, so is it just trivial ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes there are genuine reasons to want to add components to a JLabel. Since it is trivially easy to set and swap ImageIcons on JLabels, it's not uncommon to want to use them as a backing image for your GUI.

Edit
You state:

Ahha mean to say, If I wanted my container to have a specific background, then I must be using JLabel as the platform, on which such things can reside ? Am I right ?

No, you don't absolutely have to use a JLabel for this as it is fairly easy to draw a background image in a JPanel if desired. Just draw the image in its paintComponent(...) method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...