Я сделал кнопку, где вы можете выбрать файл, который вы хотите, но я хочу сделать только изображения, показанные на первой кнопке, и только веб-страницы во втором, поэтому пользователь не может выбирать других, но он не будет работать ,Как я могу выбрать, что должен показать FileFilter, когда я нахожусь в файле filechooser?
JButton btnImage = new JButton("Parcourir");
btnImage.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser openFile = new JFileChooser();
int result = openFile.showOpenDialog(null);
String path= "";
String source ;
if (result == JFileChooser.APPROVE_OPTION) {
openFile.addChoosableFileFilter(new FileNameExtensionFilter("Image Files", "png","GIF", "jpg"));
File selectedFile = openFile.getSelectedFile();
textField_1.setText(selectedFile.getName());
path = selectedFile.getName();
source = "<li><img src=" +path+ "id='nnm' style='width:100%;height:100%;'></li>";
}else {
JOptionPane.showMessageDialog(null, "You have to choose a file ");
}
}
});
btnImage.setVisible(false);
btnImage.setBounds(236, 223, 89, 23);
frame.getContentPane().add(btnImage);
btnPageWeb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser openFile = new JFileChooser();
int result = openFile.showOpenDialog(null);
String path;
String source ;
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = openFile.getSelectedFile();
textField_1.setText(selectedFile.getName());
path = selectedFile.getName();
source = "<li><iframe src="+path+"frameborder='0' id='nnm' style= 'width:100%;height:100%;' ></iframe></li>";
}else {
JOptionPane.showMessageDialog(null, "You have to choose a file ");
}
}
});
btnPageWeb.setVisible(false);
btnPageWeb.setBounds(246, 250, 89, 23);
frame.getContentPane().add(btnPageWeb);
Полный компилируемый класс был бы замечательным. :-) – Amber