aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Combine multiple jtextfield values into one. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Combine multiple jtextfield values into one." Watch "Combine multiple jtextfield values into one." New topic

Combine multiple jtextfield values into one.

N Hakim

Joined: Aug 01, 2013
Posts: 4
Hi. Im making an address book program. I have 4 input, where the user will type in Name, Admin No, Phone No and Email. How do I combine all these input to show in one jtextfield?

Rob Spoor

Joined: Oct 27, 2005
Posts: 19541

You don't. A JTextField is meant to only show one line. To show multiple lines, use a non-editable JTextArea or perhaps even a JLabel. For the JLabel you would need to wrap the contents in HTML so you can use line breaks. For instance:
(without the HTML pieces, everything will be shown on one line)

Perhaps even better is to use a JPanel with a GridLayout where you put in 4 JLabels with the 4 values.

How To Ask Questions How To Answer Questions
N Hakim

Joined: Aug 01, 2013
Posts: 4
Okay. It worked. Thank you. But I have another question. Since this is an address book program, for example after I type in Name : John, Admin No: 20, Phone No: 123, Email: abc and these information will be shown in the jtextarea, how do I put another information in the same jtextarea without clearing this existing John information?
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4339

you probably want to save your JTextArea's in an array or ArrayList or other collection.

Visit my download page
Don't get me started about those stupid light bulbs.
subject: Combine multiple jtextfield values into one.
Similar Threads
JOptionsPane not outputting info to console
cant change background color of applet with button click
Java Address Book : How to get jtextfield text from another class?
calling another swing application to run when a button is click from my swing application
SQL INSERT Statement in java