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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Combine multiple jtextfield values into one." Watch "Combine multiple jtextfield values into one." New topic
Author

Combine multiple jtextfield values into one.

N Hakim
Greenhorn

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
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
N Hakim
Greenhorn

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: 4347
    
    2

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


SCJP
Visit my download page
 
Consider Paul's rocket mass heater.
 
subject: Combine multiple jtextfield values into one.