Results 1 to 2 of 2
Thread: Need help with JCOMBOBOX
- 03-31-2011, 08:56 AM #1Member
- Join Date
- Mar 2011
- Rep Power
Need help with JCOMBOBOX
Hello to all!
I need your help with JcomboBox, while setting files in it.
Examine following code:
File file_list = getFileList();
JComboBox box = new JComboBox(file_list);
JFrame frame = new JFrame();
Assume getFileList() is a function that returns an list of files residing in a specific directory and cannot be changed.
Above code displays a frame with a combo box where I can choose between all the files.
My problem is the files are shown with their full path (for example c:\documents and settings\administrator\.....) which could be very long and pointless since they're all in the same directory.
I want to see only the file name.
Said that there are 2 ways to fix the above code.
Values in combobox should still be files, meaning I will be able to do:
File f = (File)box.getSelectedValue();
I have searched many forums, books but still not find any solution.
Will very much appreciate your help!
- 03-31-2011, 09:17 AM #2
- By bahumbaba in forum AWT / SwingReplies: 2Last Post: 12-10-2009, 02:58 PM
- By pinks_70986 in forum New To JavaReplies: 2Last Post: 02-19-2009, 06:26 PM
- By daniel50096230 in forum NetBeansReplies: 1Last Post: 09-21-2008, 12:23 PM
- By Fosters in forum AWT / SwingReplies: 0Last Post: 08-10-2008, 01:22 PM
- By Freddie in forum AWT / SwingReplies: 4Last Post: 05-11-2007, 12:48 AM