I can't open a file by just writing the file's name in the JFileChooser unless I'm in the same folder as it, what can I do to fix it?
JDialog.setDefaultLookAndFeelDecorated(true);
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
FileFilter imageFilter = new FileNameExtensionFilter("Image files", ImageIO.getReaderFileSuffixes());
chooser.setFileFilter(imageFilter);
File file = chooser.getSelectedFile();
String filePath = file.getAbsolutePath();
icon = new ImageIcon(filePath);
try{
original = ImageIO.read(file);
image = ImageIO.read(file);
width = image.getWidth();
height = image.getHeight();
if (width > 1000 && height > 1000){
image = null;
JOptionPane.showMessageDialog(null, "Image is too big (maximum 1000px by 1000px)", "Message: ", JOptionPane.INFORMATION_MESSAGE);
} else if (width > 1000 && height <= 1000) {
image = null;
JOptionPane.showMessageDialog(null, "Width is too big (maximum 1000px)", "Message: ", JOptionPane.INFORMATION_MESSAGE);
} else if (width <= 1000 && height > 1000) {
image = null;
JOptionPane.showMessageDialog(null, "Height is too big (maximum 1000px)", "Message: ", JOptionPane.INFORMATION_MESSAGE);
}
} catch (IOException e) {
System.out.println(e);
}
picture = new ImageIcon(image);
label.setIcon(picture);
}