This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Combine multiple jtextfield values into one.

 
N Hakim
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
N Hakim
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4391
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you probably want to save your JTextArea's in an array or ArrayList or other collection.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic