Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)


    Hello
    My names Harry, and im a beginner in Java programming, i have taken a few courses so know some of the terms and lingo and how to build a basic program.
    i am currently working on a GUI app, which is why im here, i have managed to make this App button less, so that the information i want to display just does, without having to do anything apart from run it, the information is displayed in 'JTextFields' ontop of a 'JLabel' there are 20 so TextFields, each of these display a line of writing, however the lines of writing are in seperate notepad files, i would like to code it so that it will read the first line of a notepad and then put it in a textfield and then read the 2nd line of writing and display it in a different textfield, and the same for the other 18 or so. i am working my way up to being able to take information from a CSV(comma seperated file).

    Is there a way to display information in the same CSV file in different textfields, and if these numbers get changed, how would i go about making it automatically update?

    Any help/Soruce code etc., would be very helpful.

    ================================================== ==============================
    Example of my code.(if this helps)
    ================================================== ==============================
    This part of my code creates and puts the textfield in a certain location, and then goes into "MyFile" to read the information and display it into the "TxtCardiff" JTextFieldThis works fine, and i have this same code repeated 20 times, and have 20 different notepad files, i need to put all information into one file, and still display it into the different textfields!)
    txtCardiff = new JTextField();
    		try {
    			FileReader MyFileReader = new FileReader(
    					"MyFile");
    			int character = MyFileReader.read();
    			while (character != -1) {
    				output += (char) character;
    				character = MyFileReader.read();
    			}
    			MyFileReader.close();
    		} catch (IOException e1) {
    			System.out.println(e1.getMessage());
    		}
    		txtCardiff.setText(output);
     
    		txtCardiff.setText(output);
    		txtCardiff.setBackground(Color.GREEN);
    		txtCardiff.setBounds(305, 699, 102, 20);
    		frame.getContentPane().add(txtCardiff);
    		txtCardiff.setColumns(10);
    ================================================== ==============================

    Regards,
    Harry




  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    display information in the same CSV file in different textfields
    There is no restriction on how many different textfields that Strings can be added to.
    if these numbers get changed, how would i go about making it automatically update?
    There are listeners that can be added to the textfields that can be called when there are changes made.
    The listeners can do the update.


    Please use normal text for posting questions. The ALL caps and large font makes it hard to read the post.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    Sorry about the large text, didnt realise it would be that big.

    do you know what listeners i would be using because i have looked into it and the only one i have come across is when you select the textfield and hit the enter key.

    i dont think i made myself clear,
    i wanted help with how to display single lines of text in different textfeilds from a csv with all the infromation in it.

    E.g.
    -----------------------------------
    CSVfile
    cardiff:234567
    bristol:546734
    manchester:458675
    -----------------------------------
    and then display each of these locations into 3 different textfields.

    Regards

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    how to display single lines of text in different textfeilds
    I don't understand what the problem is. A String can be added to any number of textfields. There are no restrictions.

    pseudo code:
    read string
    add string to tf1
    add string to tf2
    add string to tf3
    etc

    or when the strings are to be round robined into different tf:

    begin loop
    read string
    add string to next tf
    end loop
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    Yes i know there are no restrictions.

    but how do i take the strings from the CSV file, and display them in seperate TextFields?
    each textfield is going to have different information in it,

    i know what to do just not how:

    go to file
    read first line
    display line in tf1
    read 2nd line
    display line2 in tf2
    etc....
    but i dont know how to code this
    this also needs to be looped every 10-20 seconds to make sure nothing has changed.

    Does that make it clear?
    sorry im new to this forum stuff.

    Regards,

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    go to file
    read first line
    display line in tf1
    read 2nd line
    display line2 in tf2
    etc....
    but i dont know how to code this
    Which of the steps are you having problems with?

    How do you decide which tf to add a String to? Can the tf be referenced from an array?
    Inside a loop the Strings could be read from the file and added to the next tf from the array.

    make sure nothing has changed.
    Where are the changes being made? To the file's contents or to the textfields?
    You can use listeners to detect changes.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    I am having problems taking data from a CSV file and then
    outputting the different lines of information into different textfields

    i dont know how to decide it or if it can be referenced thats why i put this question up, so that i can to find out:

    - How to extract data from a csv file and put each line of the file into a different TextField.

    And changes will be made to the Files contents. and when this happens i want the textfield to update.
    i know i can use listeners to do all sorts of things, but i dont know which listeners i need.

    Regards,

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    Let's work on the problems one at a time. Start with this one:
    How to extract data from a csv file
    The Scanner class is easy to use for reading lines from a file. Define a Scanner object to read from the file.
    Write a loop to read lines from the file and print them out.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    I was able to do this with a single file that had multiple lines of code and display them in one place, however i dont know how to take different lines of this file and display them in different locations.

    By the way, thank you for all your help

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    how to take different lines of this file and display them in different locations.
    What determines what location a line is to be displayed in? See post#4 for some considerations.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    So i will have a Textfield on a Map on the location of Cardiff, the information in the textfield will then say Cardiff:5463965, and one for Bristol, one for london, one for manchester etc,

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    What determines what location a line is to be displayed in?
    When a line is read from the file, how will the program decide which tf to add the line to? Is there something in the line that will determine that?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Feb 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    I dont have anything to determine this, the only thing that i can use to determine this will be a comma,

    Or i could use the fact that each line will have a different location on it, would that work?

    Is there a way to make it so the program will look for say the word 'Manchester', and then display the line with the word 'Manchester' on it to a particular tf ?

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NEED TO EXTRACT FROM CSV FILE PUT INTO JTEXTFIELDS (JAVA SWING GUI)

    the only thing that i can use to determine this will be a comma,
    If every line has one or more commas, how can a comma be used to select the tf to put the line in?

    look for say the word 'Manchester',
    Look at the methods in the String class. There are some that can be used to check if a String contains another String.

    I don't
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. extract selected text out of a pdf file using java
    By ashish.sharma in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 2nd, 2013, 04:01 AM
  2. read csv file in java
    By kishore1981 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 6th, 2012, 07:52 AM
  3. Binary File. Extract float data from binary file and put into array
    By cardinal152 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: June 13th, 2012, 07:31 PM
  4. OpenGL with Swing/AWT/ whatever Java gui
    By Lablabla in forum AWT / Java Swing
    Replies: 1
    Last Post: May 4th, 2012, 09:15 AM
  5. Replies: 6
    Last Post: January 28th, 2011, 01:13 AM

Tags for this Thread