I have a problem with my JComboBox.
description:
I create a new file by writing the name of my file in a Textfield. By clicking on a button I create a file with this value and add this into my JComboBox, but I only see the Object value, for example "[Ljava.io.FIle;@1b1428d" and that's the problem. The user doesn't even know what this value means so I need my filename. I searched for a long time and Yes the toString()
doesn't work :D
My Code looks like this: JComboBox TxtDoc = new JComboBox(create());
public File[] create(){
FileSystemView SYSTEM = FileSystemView.getFileSystemView();
String user = System.getProperty("user.home")+"\\notes";
File userdir = new File(user);
File[] fileList = SYSTEM.getFiles(userdir, true);
return fileList;
}
newTxt.addMouseListener(new MouseAdapter() {
@SuppressWarnings("unchecked")
public void mouseClicked(MouseEvent event){
new Documents().createTxtDoc(); // <-- this just open a new frame with my textfield and a button.
TxtDoc.addItem(create());
}
});
thank you for your help regards Blank
iterate over it:
for (File f : fileList) {
TxtDoc.addItem(f);
}