我想在我的JPanel上有圖像,在我的JPanel上也有組件,例如JSlider和JRadioButton。正如你所看到的,我從JPanel派生了一個類並重寫了方法paintComponent。這是在JPanel上顯示圖像的好方法。JPanel圖像和組件
public void paintComponent(Graphics g)
{
/*create image icon to get image*/
ImageIcon imageicon = new ImageIcon(imageFile); //getClass().getResource(imageFile)
Image image = imageicon.getImage();
/*Draw image on the panel*/
super.paintComponent(g);
if (image != null)
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
但是我有一些問題。當我在ImagePanel上添加JSlider,JRadioButton或其他JPanel組件時,這個組件的背景保持爲默認值,而不是背景圖片。我不知道如何設置這個圖像作爲這個組件的背景。 請指導我。
問候
非常感謝你.. damet garm rafigh !!! – sajad 2011-02-01 09:28:48