• Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane/Breaking up strings

 
Michael Smithy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jumping straight to the point...
I'm trying to break up the string into 3 different lines to be displayed on JOptionPane.showInputDialog


String Address;
Address = first_name + " " + last_name + house_number + " " + street + town + " " + input;


The code only displays the string on 1 line.
Example: Jose Reyes 13-07 Estates Lane Bayside, NY 11360


The Goal
Jose Reyes
13-07 Estates Lane
Bayside, NY 11360


Help???
 
Roel De Nijs
Sheriff
Posts: 10763
147
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First of all, a warm welcome to CodeRanch!

Joe Bot wrote:The Goal
Jose Reyes
13-07 Estates Lane
Bayside, NY 11360

From the javadoc of JOptionPane you should be able to pass the strings in an array which will be represented as a vertical stack. That sounds exactly what you need. So this should to the trickAnother alternative is of course to use the line seperator (instead of spaces) appropriately.

Hope it hellps!
Kind regards,
Roel
 
John Pacuta
Greenhorn
Posts: 26
1
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A typical Greenhorn solution: what if you used a newline?



But it seems too much like hardcoding. Roel's solution seems nicer and it uses a property of JOptionPane. Mine might not even compile!
 
Roel De Nijs
Sheriff
Posts: 10763
147
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Pacuta wrote:But it seems too much like hardcoding. Roel's solution seems nicer and it uses a property of JOptionPane. Mine might not even compile!

No worries! Your solution does compile And if you are worried about hardcoding, you could use this statement to get a system-dependent line separator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!