#JFrame image

1 messages · Page 1 of 1 (latest)

feral groveBOT
#

<@&987246487241105418> please have a look, thanks.

ebon flare
#

Why does the image show up like this?

feral groveBOT
# ebon flare

I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.

old hornet
#

Because you coded it like that. What's your expectation instead?

ebon flare
old hornet
sweet surge
#

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

paper crescent
#

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);
}

}`