File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Loading/Saving a Listbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Loading/Saving a Listbox" Watch "Loading/Saving a Listbox" New topic
Author

Loading/Saving a Listbox

Steven Alvarez
Ranch Hand

Joined: Nov 01, 2006
Posts: 66
How can I add/save to a listbox?

For example if the data was straight like:

data1
data2
data3
etc

How can I save that and load that? Thanks!
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Steven Alvarez
Ranch Hand

Joined: Nov 01, 2006
Posts: 66
I may have confused you. Sorry. But I need a function that allows me to open up a file diaglog box, choose the file, and then load this text file into a listbox. I also need another function that does the same thing but for saving the information in a listbox to a text file. Thanks.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
The term listbox is new to me. We have JList in Swing and a similar class List in the AWT. Could you say more about listbox - what is it, how does it work, what does it look like? Maybe we can make up or suggest something that will do what you want.
Or, if you want to use Swing there is a page that shows available components by type: A Visual Index to the Swing Components.
Both Swing and the AWT have file dialog components: JFileChooser and FileDialog.
Steven Alvarez
Ranch Hand

Joined: Nov 01, 2006
Posts: 66
Thats extactly what I need. TO load/save text files into a Jlist.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
To learn more about customizing JFileChooser see How to Use File Choosers.
For IO (reading and writing) see Lesson: Basic I/O.
For info on the Scanner class lookup the api class listing in the javadocs and also Scanning.
Steven Alvarez
Ranch Hand

Joined: Nov 01, 2006
Posts: 66
Thanks to Craig Wood I have the following function:




This is good for JList's but I need it to work with AWT Lists. However there is no function called "getElementAt" Could someone please convert this function for me? Thanks!!
[ March 16, 2007: Message edited by: Steven Alvarez ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
You can find the equivalent methods in the java.awt.List class api.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading/Saving a Listbox