My project is Open an image and Save it again, I use ImageIcon,JLabel and JPanel to display it (I used ImageIcon and JPanel, but It didn't work, ImageIcon could not add to JPanel). when I open it, It always display the image but not full size to JFrame. this code I write in class OpenImage extends JFrame
public class Draw_JPanel extends JFrame{
Load_image panel_im = new Load_image();
public void OpenImage()
{
JFileChooser fc = new JFileChooser();
int result = fc.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
String name = file.getName();
try {
image = ImageIO.read(file);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
imageic = new ImageIcon(image);
height1 = imageic.getIconHeight();
width1 = imageic.getIconWidth();
picLabel = new JLabel(new ImageIcon(image));
panel_im.add(picLabel,BorderLayout.CENTER);
}
this.pack();
}
and the code of Load_image class
public class Load_image extends JPanel{
public Load_image()
{
this.setBackground(Color.RED);
}
}
Sorry but I can't upload image