I trying to create a GUI as image below
However, when I run my file, the size of the image still remain the original size
How can I reduce the size of the image so I can add text beside ?
public class HomePage extends JFrame {
public static void main(String[] args) throws IOException {
new HomePage();
}
public HomePage() throws IOException {
this.setTitle("Picture Application");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setBackground(Color.yellow);
BufferedImage myPicture = ImageIO.read(new File("C:\\Users\\seng\\Desktop\\logo.png"));
myPicture.getScaledInstance(10,30,Image.SCALE_SMOOTH);
JLabel picLabel = new JLabel(new ImageIcon(myPicture));
add(picLabel);
this.pack();
this.setVisible(true);
}
}
myPicture.getScaledInstance(10,30,Image.SCALE_SMOOTH);
The above statement returns a new BufferedImage which you never reference.
The code should be:
//myPicture.getScaledInstance(10,30,Image.SCALE_SMOOTH);
Image scaled = myPicture.getScaledInstance(10,30,Image.SCALE_SMOOTH);
JLabel picLabel = new JLabel(new ImageIcon(scaled));