Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading/Saving a Listbox

 
Steven Alvarez
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Steven Alvarez
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats extactly what I need. TO load/save text files into a Jlist.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find the equivalent methods in the java.awt.List class api.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic