File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 19651

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: 4340

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

Visit my download page
jQuery in Action, 2nd edition
subject: Combine multiple jtextfield values into one.
Similar Threads
cant change background color of applet with button click
calling another swing application to run when a button is click from my swing application
Java Address Book : How to get jtextfield text from another class?
SQL INSERT Statement in java
JOptionsPane not outputting info to console