OK, hello guys.
I'm trying to make an image fit a JPanel. What I mean is to set a maximum size on a image, depending on how big the JPanel is.
I'm using a JSplitPane to show some images. On the lef side I'm using a JList, and on the right I'm using a GridLayout(2,1) with a JPanel and JTextArea. For each picture I select, I want a description. The thing is, I managed to show the picture in the JPanel with text etc. B
But if I put a small pic, it's small. If I put a big picture, I can't see the whole picture. I want to set a size on my pictures so it fills the JPanel without missing any content. I don't care if the pictures get bad quality (for example a small picture would get bad quality if it's resized to fit a big JPanel).
But I'm not quite sure how I can do this.
At the moment, this is how I upload the image.
if(result == JFileChooser.APPROVE_OPTION) {
thePanel.removeAll();
thePanel.repaint();
File image = chooser.getSelectedFile();
ImageIcon photo = new ImageIcon(image.getAbsolutePath());
JLabel label = new JLabel(image.getName(), photo, JLabel.RIGHT);
thePanel.add(label, BorderLayout.CENTER);
thePanel.repaint();
thePanel.revalidate();
return;
}
How can I make my picture big enough to fit the JPanel?
Thanks in advance.