I am currently creating a GUI for a game. I am currently loading an image using JLabel onto my JPanel, I was wondering whether it would be possible to add buttons on various parts of the image e.g. (5,7) and (12,12).
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you wish to have
JButtonsappear over your image, a better approach would be to override thepaintComponentof theJPaneland use drawImage to draw the image similar to this example . This will allow you to add components to the container.Absolute positioning(
nulllayout) is generally frowned upon for setting component locations, however. This DragLayout should be a better substitute taking care of component sizing.