I am making a Class that extends JFrame and have my custom background image on it..
I have two problems..
1) I want my background image to stay fixed sized that covers whole screen when maximized. How can I do that?
2) I want to add a transparent button and panels on 开发者_JS百科the frame that does not disturb my background. Is there any easy way to do that?
help will be greatly appreciated... thank you
Load the image into a BufferedImage
.
Add a ComponentListener
to determine when the frame is resized. Use the frame size to calculate scaling and call BufferedImage.getScaledImage(xScale, yScale)
to obtain a scaled image.
In your class you should be overriding paintBackground()
to do the painting. Just call g.drawImage(scaledImage, getWidth(), getHeight(), this) to paint the image.
Any components you add to the frame need to call setOpaque(false)
so the background gets painted underneath them.
精彩评论