Results 1 to 2 of 2
  1. #1
    Slavon is offline Member
    Join Date
    Mar 2011
    Rep Power

    Smile 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!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

Similar Threads

  1. Replies: 2
    Last Post: 12-10-2009, 01:58 PM
  2. JComboBox
    By pinks_70986 in forum New To Java
    Replies: 2
    Last Post: 02-19-2009, 05:26 PM
  3. JCombobox
    By daniel50096230 in forum NetBeans
    Replies: 1
    Last Post: 09-21-2008, 12:23 PM
  4. JComboBox
    By Fosters in forum AWT / Swing
    Replies: 0
    Last Post: 08-10-2008, 01:22 PM
  5. jcombobox
    By Freddie in forum AWT / Swing
    Replies: 4
    Last Post: 05-11-2007, 12:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts