I have a JPanel
into a JFrame
. I loaded a picture on the JPanel
but its shown just a part of the picture: This is the part of the code where i did it:
JPanel panelImg = new JPanel()
{
public void paintComponent(Graphics g)
{
Image img = new ImageIcon("Welcome.png").getImage();
Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
g.drawImage(img, 0, 0, null);
}
};
mainFrame.add(panelImg);
So this is how it looks like:
The complete picture looks like this:
Is there a way to scale the picture to the JFrame
s size? Thanks in advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…