formatiing a String !!

Now then!

I am new to all this JAVA programming so please be gentle with me!!

I am trying to do something what I think should be easy but I am having huge difficulty with it and I don抰 know where to look now!

I am trying to combine several string and text fields into one text field, move the resulting text field into a vector, then display the vector in a list box.

All of this is working, however, the way it is displayed the records appear like:

1,ABC,123.

12,DEFG,5678

I have been asked to display them as

1 ,ABC,123

12,DEFG,5678

I have tried \r, \n, \r\n in the string and none of it seams to work.

the way the fields are being populated from my SQL statement is below:

TextField supplierNumberText = new TextField(6);

String supplierNumberParm = rs.getString(1);

String supplierNameParm = rs.getString(2);

String supplierAddressParm = rs.getString(3);

String supplierPostCodeParm = rs.getString(4);

supplierNumberText.setText(supplierNumberParm);

String supplierInfo = supplierNumberText.getText()+", "+supplierNameParm+ ", "+supplierAddressParm+ ", "+supplierPosTCodeParm;

supplierNameVector.addElement(supplierInfo);

Any useful advice, (or should that be constructive!!) would be most appreciated!

[1334 byte] By [MartGibsa] at [2007-11-26 15:31:11]
# 1

don't you hate formatting !!

I meant to say i want all the data to appear on top of each other

so column 1 would be

1 ,

12,

coumn 2 would be

ABC,

DEFG ,

and column 3

123

5678

not as the are now.

god i hope this makes sence!

MartGibsa at 2007-7-8 21:48:02 > top of Java-index,Java Essentials,Java Programming...
# 2
Use a JTable...
es5f2000a at 2007-7-8 21:48:02 > top of Java-index,Java Essentials,Java Programming...
# 3
1. You need to pad your strings with the right numbers of spaces. This is not hard to do directly, but you could also use the java.util.Formatter class: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html2. In your component, don't forget to use a fixed-width
DrLaszloJamfa at 2007-7-8 21:48:02 > top of Java-index,Java Essentials,Java Programming...
# 4

You can preserve whitespace in your posts by enclosing the text in [pre] [/pre] tags. And if you post source code, please use [code] [/code] tags.

As DrL said, java.util.Formatter is probably the solution to your problem. It can also be used by way of the format() method in class String.

uncle_alicea at 2007-7-8 21:48:02 > top of Java-index,Java Essentials,Java Programming...