#JFrame image
1 messages · Page 1 of 1 (latest)
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
Because you coded it like that. What's your expectation instead?
where did I code it like that
#1320363532109222000 message
its a bit hard to help explaining sth that's obvious to us if u can't point the finger on what's not obvious to u or explain what u expected to happen instead
perhaps u start with that and explain what u thought the code would do
then we can tell u why it's not doing that
and how to change it to do what u wanted
JLabel is taking your image and putting it in as the size of the image. To draw it at a different size use a paintComponent method and use drawImage
FlowLayout also just puts your items next to each other automatically so it's saying "put your first button down, then next to it the second one then, then the third, then next to it the image"
I'm pretty new to this, probably the same as you, so I can't confirm it but I think paintComponent is a method of JPanel so you'll need to make a class that extends JPanel and then just like you added all your other components, add your other class(which will be seen as a JPanel since it's a child of one)
`public class BackgroundImage extends JPanel{
private Image backgroundImage;
Public BackgroundImage(String path){
backgroundImage = new ImageIcon(path).getImage()
}
@Override
public void paintComponent(Graphics g){
super.paintComponent(g)
g.drawImage(backgroundImage, 0, 0, this.getWidth(), this.getHeight(), this);
}
}`