Displaying Background Image in Swing Components
Eg 1: Add background image to JTextArea
JTextArea textArea = new JTextArea() {
ImageIcon backImage = new ImageIcon("Resources/Background.jpg");
Image image = backImage.getImage();
{setOpaque(false);}
//Override
public void paintComponent (Graphics g) {
g.drawImage(image, 0, 0, this);
super.paintComponent(g);
}
};
Eg 2: Add background image to JDesktopPaneJDesktopPane textArea = new JDesktopPane() {
ImageIcon backImage = new ImageIcon("Resources/Background.jpg");
Image image = backImage.getImage();
{setOpaque(false);}
//Override
public void paintComponent (Graphics g) {
g.drawImage(image, 0, 0, this);
super.paintComponent(g);
}
};
We can use this method to add background images to any Swing component.
Thank You so Much!!!!! I couldn't find out how to do this anywhere!!!
Indeed, thank you very much!
Indeed, thank you very much!
Is it possible to change the background image once a button is clicked? 'Cause based on the code, the way I see it, it seems impossible.
Post a Comment