Friday, June 21, 2019

java - How to set background image for JPanel in netbeans?





i am using netbeans IDE problem is how to set background image for JPanel without using JLabel. Can anyone tell me how to do this?


Answer



This is fairly straight forward.



public class ImagePanel extends JPanel{
Image image;

public ImagePanel(Image image){
this.image = image;
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0,0, this);
}
}



If you want more complex have a look at this link. This has a couple of settings like fit image to panel...


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...