aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Need help populating a JList in NetBeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Need help populating a JList in NetBeans" Watch "Need help populating a JList in NetBeans" New topic
Author

Need help populating a JList in NetBeans

Greg Pritchard
Greenhorn

Joined: Jun 24, 2013
Posts: 3
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!
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1096
    
  10

Hi Greg,
Welcome to the Ranch!

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


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Ganesh Malaichamy
Greenhorn

Joined: Feb 11, 2011
Posts: 27
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

Joined: Jun 24, 2013
Posts: 3
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

Joined: Jun 24, 2013
Posts: 3
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help populating a JList in NetBeans