Reputation: 75
I am making an application that applies a filter to a picture. It asks the user where to save the new file immediately after selecting a source file. Is it possible to prepopulate the save dialog box with the source file name + _filtername?
Upvotes: 2
Views: 177
Reputation: 2322
This example for Open Dialog
JFileChooser fd = new JFileChooser();
fd.showOpenDialog(this);
if(fd.getSelectedFile()==null&&pro_pic_text.getText().toString().trim().equals(""))
{
JOptionPane.showMessageDialog(this,"Choose your Profile Picrure","Warning",JOptionPane.WARNING_MESSAGE);
}
else
{
fileName = fd.getSelectedFile().getAbsolutePath();
File ff = new File(fileName);
String ffname = ff.getName();
int aa = ffname.indexOf(".");
fftype = ffname.substring(aa+1);
if(fftype.equals("png") || fftype.equals("PNG") || fftype.equals("JPEG") || fftype.equals("jpeg") || fftype.equals("JPG") || fftype.equals("jpg"))
{
if(ff.length()<=51300)
{
pro_pic_text.setText(fileName);
}
else
{
JOptionPane.showMessageDialog(this,"File size larger then 50kb not allowed","Warning",JOptionPane.WARNING_MESSAGE);
pro_pic_text.setText("");
}
}
else
{
JOptionPane.showMessageDialog(this,"Choose JPEG, JPG or PNG File","Warning",JOptionPane.WARNING_MESSAGE);
pro_pic_text.setText("");
}
}
Use this code my english is bad
this code have some validation like Supported file must have less then 50KB and only JPEG,jpeg,jpg,JPG,PNG,png file
I thing this is helping for you
Upvotes: 0
Reputation: 347184
Start by having a read through How to Use File Choosers.
You want to use JFileChooser#setSelectedFile
Upvotes: 2