Recent:
Archives:
Enterprise Java Newsletter Stay up to date on the latest tutorials and Java community news posted on JavaWorld
Who can tell me how make an image background for jframe by using netbeans?
using netbeans not other!
Hi,
you can overwrite the paintComponent-method of the JFrame:
_background = new ImageIcon(getClass().getClassLoader().getResource("background.jpg"));...protected void paintComponent(final Graphics g) { super.paintComponent(g); int alignmentX = getWidth() - _background.getImage().getWidth(this); int alignmentY = getHeight() - _background.getImage().getHeight(this); g.drawImage(_background.getImage(), alignmentX, alignmentY, this);}
Bye, Torsten
Thank you very much! I solved this problem successfully!
Nope, Torsten did! You just implemented it :)
I also didn't solve it by myself but found it by the help of google ;-).
ImageIcon Img = new ImageIcon(<path to icon>);JFrame Frame;Frame.setBackground(Img);
I think that is how we used to do it when we did guis in class. Hope I helped. (Lot lighter than the last suggestion.)
More information about formatting options
Background
Hi,
you can overwrite the paintComponent-method of the JFrame:
_background = new ImageIcon(getClass().getClassLoader().getResource("background.jpg"));
...
protected void paintComponent(final Graphics g) {
super.paintComponent(g);
int alignmentX = getWidth() - _background.getImage().getWidth(this);
int alignmentY = getHeight() - _background.getImage().getHeight(this);
g.drawImage(_background.getImage(), alignmentX, alignmentY, this);
}
Bye,
Torsten
reply to Torsten
Thank you very much!
I solved this problem successfully!
Torsten
Nope, Torsten did! You just implemented it :)
To be honest ...
I also didn't solve it by myself but found it by the help of google ;-).
I think this works to though it has been awhile
ImageIcon Img = new ImageIcon(<path to icon>);JFrame Frame;
Frame.setBackground(Img);
I think that is how we used to do it when we did guis in class. Hope I helped. (Lot lighter than the last suggestion.)
Post new comment