Results 1 to 4 of 4
  1. #1
    Ekul is offline Member
    Join Date
    Nov 2009
    Posts
    5
    Rep Power
    0

    Default taking data from several textfields and combining them to be one item in a JList

    how would i go about collecting data from 4 JTextFields such as name,address, home num, mobile num. and then combining them into one string so they can be one item in a JList? eg

    luke, highway road, 929382094, 03740324

    any help would be great thanks

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Get the contents of each of the text fields, use the + operator to create a new string (or String.format()) and then add that string as an element of the list.

    It's hard to see what the actual problem is here. (Unfamiliarity with String operations? with Swing? with the particular methods of lists and text fields?) Perhaps you could post your attempt.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,337
    Blog Entries
    7
    Rep Power
    20

    Default

    Java Code:
    JTextField tf1, tf2, tf3, tf4;
    ...
    String result= tf1.getText()+", "+tf2.getText()+", "+tf3.getText()+", "+tf4.getText();
    kind regards,

    Jos

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,233
    Rep Power
    7

    Default

    A better approach would be to use a JTable (instead of the JList). Then the data from each text field represents a column in the table and you update the TableModel by using the addRow(...) method of the DefaultTableModel.

Similar Threads

  1. Buttons and TextFields
    By Xystus777 in forum New To Java
    Replies: 27
    Last Post: 03-17-2009, 01:26 AM
  2. Replies: 0
    Last Post: 02-28-2009, 11:16 AM
  3. Replies: 0
    Last Post: 02-11-2009, 11:12 PM
  4. Help combining loops into 1 program.
    By kewlgeye in forum New To Java
    Replies: 5
    Last Post: 04-22-2008, 09:58 AM
  5. information from a textfields
    By bbq in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-28-2007, 05:28 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
  •