Results 1 to 2 of 2
- 12-01-2010, 06:20 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 5
- Rep Power
- 0
Display only certain contents of text file and edit display
I have a text file with data entered as:
0,Broyles, Frank, 479-575-1964, Football St, Fayetteville, AR, 72703
1,Richardson, Nolan, 479-575-1994, Basketball St, Fayetteville, AR, 72703
I want to display only certain contents of the file in this format to a jlist:
Last name, First name
Phone number
City, State, zip code
How do I do this? It think it would be possible for me to edit the entry of the data to use a delimiter for display, such as a comma. I've fiddled with using a comma delimiter in the scanner class but can't seem to get it to work either.
Any ideas? ThanksJava Code:private class ViewVidButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { try { FileReader a=new FileReader ("video.txt"); Scanner b=new Scanner(a); int arraySize=0; while(b.hasNextLine()) { b.nextLine(); arraySize++; } String[]c=new String[arraySize]; a=new FileReader("video.txt"); b=new Scanner(a); int d=0; while(b.hasNextLine()) { String f=b.nextLine(); c[d]=f; d++; } JFrame f=new JFrame("View Videos"); JList g=new JList(c); f.getContentPane().add(g); f.setSize(400,400); f.setLocationRelativeTo(null); f.setVisible(true); } catch(Exception exception) { exception.printStackTrace(); } } }
-
This might help you: JList can take HTML Strings and will break lines with <br>:
Java Code:Vector<String> vect = new Vector<String>(); vect.add("<html>hello World!<br>WTF???</html>"); vect.add("<html>Goodbye World!<br>Parting is such sweet sorrow!</html>"); vect.add("<html>Look ma!<br>I'm on top of the world!!</html>"); JList jlist = new JList(vect); JOptionPane.showMessageDialog(null, new JScrollPane(jlist));
Similar Threads
-
What is the different between Text format display on web browser and display on midle
By Basit781 in forum CLDC and MIDPReplies: 1Last Post: 05-31-2010, 08:46 AM -
How can I get the file contents to display as readable text?
By xtiano77 in forum New To JavaReplies: 6Last Post: 03-12-2010, 04:54 AM -
Display partial file contents in JTextArea
By tmoehlman in forum New To JavaReplies: 0Last Post: 11-02-2009, 11:03 PM -
problem trying to display the contents of a text file in JTextArea
By warship in forum New To JavaReplies: 17Last Post: 07-13-2009, 05:44 AM -
Display the contents of a file on jsp page
By shiva in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-30-2009, 01:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks