Results 1 to 2 of 2
  1. #1
    blkshrk81 is offline Member
    Join Date
    Nov 2010
    Posts
    5
    Rep Power
    0

    Default 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.

    Java 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();
    				}
    			}
    		}
    Any ideas? Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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

  1. Replies: 1
    Last Post: 05-31-2010, 08:46 AM
  2. Replies: 6
    Last Post: 03-12-2010, 04:54 AM
  3. Display partial file contents in JTextArea
    By tmoehlman in forum New To Java
    Replies: 0
    Last Post: 11-02-2009, 11:03 PM
  4. Replies: 17
    Last Post: 07-13-2009, 05:44 AM
  5. Display the contents of a file on jsp page
    By shiva in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-30-2009, 01:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •