So I am trying to have a user select multiple photos out of a directory. From the main GUI I open a window that lets the user select name and ID and then I use JFileChooser to get the photos. Everything works out so far - I just can't select more than one file at a time which entirely defeats the purpose of this. Nothing is doable: Ctrl+Click or Shift+Arrowkeys. I already looked around that seems to be a popular problem.
My running version will include said GUI-Elements. Please explain to me how to make the selection of multiple files at once possible and if possible how this behaviour comes into existence.
JDialog ImportFenster= new JDialog(Fenster,
"Import von Nutzern");//Fenster is here the main GUI window use another one or set the first parameter here to "null"
JTextField Name= new JTextField("Vorname [Leer] Name",30);
JFormattedTextField ID =new JFormattedTextField(
NumberFormat.getIntegerInstance());
ID.setColumns(4);
JButton Enter = new JButton("OK");
JButton Abort =new JButton("Abbruch");
JLabel InfoID= new JLabel("Wird keine ID angegeben, wird eine automatisch erzeugt");
//kinda stupid way to make your layout
GridBagLayout ImportLayout= new GridBagLayout();
GridBagConstraints LayoutConstraints=new GridBagConstraints();
ImportFenster.setLayout(ImportLayout);
LayoutConstraints.fill=GridBagConstraints.VERTICAL;
LayoutConstraints.gridwidth=3;
LayoutConstraints.gridx=0;
LayoutConstraints.gridy=0;
LayoutConstraints.ipadx=5;
LayoutConstraints.ipady=5;
ImportFenster.add(InfoID,LayoutConstraints);
LayoutConstraints.gridwidth=1;
LayoutConstraints.ipadx=10;
LayoutConstraints.ipady=25;
LayoutConstraints.gridx=1;
LayoutConstraints.gridy=1;
ImportFenster.add(ID,LayoutConstraints);
LayoutConstraints.ipadx=10;
LayoutConstraints.ipady=25;
LayoutConstraints.gridx=1;
LayoutConstraints.gridy=2;
ImportFenster.add(Name,LayoutConstraints);
LayoutConstraints.ipadx=10;
LayoutConstraints.ipady=25;
LayoutConstraints.gridx=3;
LayoutConstraints.gridy=3;
ImportFenster.add(Enter,LayoutConstraints);
LayoutConstraints.ipadx=10;
LayoutConstraints.ipady=25;
LayoutConstraints.gridx=0;
LayoutConstraints.gridy=3;
ImportFenster.add(Abort,LayoutConstraints);
LayoutConstraints.gridx=0;
LayoutConstraints.gridy=1;
ImportFenster.add(new JLabel("Nutzer-ID:"),LayoutConstraints);
LayoutConstraints.gridx=0;
LayoutConstraints.gridy=2;
ImportFenster.add(new JLabel("Nutzer-Name:"),LayoutConstraints);
ImportFenster.setSize(750,350);
ImportFenster.setVisible(true);
Enter.addActionListener(new ActionListener() { //before this the codes does some shit DateiAuswahl.showOpenDialog(Fenster);
DateiAuswahl.setMultiSelectionEnabled(true);
DateiAuswahl.setVisible(true);
DateiAuswahl.setFileSelectionMode(JFileChooser.FILES_ONLY);
DateiAuswahl.setFileHidingEnabled(false);
File[] NewFaces = {};
if(DateiAuswahl.showOpenDialog(Fenster)==JFileChooser.APPROVE_OPTION){
NewFaces=DateiAuswahl.getSelectedFiles();
//after this stuff happens
}
}
EDIT: I am a dummy. Really. Put the setMultiSelectionEnabled() part before opening the dialoguie and presto! It works. Now I have to clean up some other issues...