• 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

Loading/Saving a Listbox

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Steven Alvarez
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats extactly what I need. TO load/save text files into a Jlist.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can find the equivalent methods in the java.awt.List class api.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic