Вопрос

I try to draw a .PNG Image using graphic2D.drawImage() method. And I make it right, but I've one JPanel on my Frame, and when I draw my image, it appears in background. I want it to appear on the foreground, and obviously in front of my JPanel.

Это было полезно?

Решение

Use JLayer. (http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html)

Override the paint method on the LayerUI set to the JLayer and draw your .PNG image there. Add your JPanel to the JLayer.

Другие советы

You should add one more JPanel and draw image in its paintComponent method like that.

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (yourImage != null)
            g.drawImage(yourImage, 0, 0, this);
    }

and than you can hide other JPanel and show this JPanel with setVisible() function.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top