• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help populating a JList in NetBeans

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys, I'm in the middle of creating a small program. I'm a bit of a noob when it comes to programming and I just starting playing with the NetBeans GUI builder to help out a friend with his code. So far what happens is:

1. JFrame pops up with a non-editable text field, button, JList, and empty panel.
2. User clicks button, and it prompts them to select a directory.
3. Once the user selects the directory, the program will load all files from this folder (eventually I'll set it to only allow .jpg).
4. The program will then display the directory in the text field and place the names of these files in the JList.

PROBLEM:
I'm having trouble with 4. I've been trying forever to get this thing to run. I've gotten it to display the directory correctly. But I can't seem to get the JList to load the file names from a file array. Here's some code if anyone can help.
*NOTE*: I have already declared a DefaulListModel named listModel outside of this buttons action event. The code isn't generating any errors but the JList remains empty after I click load.

text field -> directory
button -> jButton1
file chooser -> fc
string array of file names -> fileNames
file array of -> selectedFiles
JList -> fileList



Thanks in advance!
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Greg,
Welcome to the Ranch!

How did you create the JList instance? Did you set its model to the listModel instance?
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Additional code details will help.It could be a pack problem also. Need to see how you are setting the model to the JList.
 
Greg Pritchard
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Additional code details will help.It could be a pack problem also. Need to see how you are setting the model to the JList.



How did you create the JList instance? Did you set its model to the listModel instance?



Here is how the listModel is set:



And in case you guys need anymore code, I'll just go ahead and post the entire generated code section.





 
Greg Pritchard
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay guys, I found the solution. I was trying to load the folder as a file, so the list was null, which is why it wasn't displaying. I have since corrected the issue. Thanks for your help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic