Java JPanel tiled background image

前端 未结 3 1447
野性不改
野性不改 2020-12-18 08:57

I currently have the code for creating a JOptionPane that tiles an image to the background no matter the size I set it to :)

package test;
import java.awt.*;         


        
3条回答
  •  醉话见心
    2020-12-18 09:15

    You state:

    Any and all help is appreciated if there is a better way of doing it that is a lot less code that would also be great.

    That's not a lot of code actually. The only thing else I could suggest is that if the JPanel is not going to vary in size, create a background BufferedImage, draw your tiled images in that, and then draw the one background image in either your JPanel's paintComponent method, or in a JLabel's icon. If you go the latter route, then give the JLabel a layout manager so that it can act as a well-behaved container for your components. And make sure that anything on top of your tiled containers is not opaque if the image needs to show through, especially JPanels.

提交回复
热议问题