I am totally new in Java. My teacher told me to develop a simple project which includes ADD,EDIT,DELETE etc features. I have done successfully all the features but when I add any image it doesn't fit into the jLabel which I take into a Desktop Pane. It displays as its actual size not according to the jLabel size. I tried a lot with the help of internet but its not working. Here is the code I've done so far,
private void btn_browseActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
filename = f.getAbsolutePath();
ImageIcon imageIcon = new ImageIcon(new ImageIcon(filename).getImage().getScaledInstance(lbl_img.getWidth(), lbl_img.getHeight(), Image.SCALE_DEFAULT));
lbl_img.setIcon(imageIcon);
txt_imgpath.setText(filename);
try
{
File image = new File(filename);
FileInputStream fis = new FileInputStream(image);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
for(int readNum; (readNum=fis.read(buf))!=-1;)
{
bos.write(buf,0,readNum);
}
person_image=bos.toByteArray();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
}
private ImageIcon format = null;
String filename = null;
byte[] person_image = null;
I know it is a newbie type question and I am sorry for that but I really tried a lot but can't figure out what is the problem and how to solve it. Anyone please help me? :(