wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes decimal place formatting JtextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "decimal place formatting JtextField" Watch "decimal place formatting JtextField" New topic
Author

decimal place formatting JtextField

terry oliver
Greenhorn

Joined: Jan 04, 2008
Posts: 22
how do i use the String.format on a vector<Double> compiler error telling me cannot use string, need to format into JTextField 4 decimal places.

thanks

olly
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
Have you tried the toString method of vector before trying to String.format?
terry oliver
Greenhorn

Joined: Jan 04, 2008
Posts: 22
yes i did try that and the error was vector cannot be applied to string.


olly
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
Can you post your code? Are you tring to format in the JTextField or before placing the value in the JTextField?
terry oliver
Greenhorn

Joined: Jan 04, 2008
Posts: 22
the code is as follows
ed.setSecOhmsTemp(nt.getSecOhms());

ed is engineering data sheet (swing class)
nt is new transformer where all data is set

secOhms is a vector

for (int x = 0; x < secTurnsTemp.size(); x++) {

if (choice.intValue() == x+1) {
secTurns1.setText(((Double)secTurnsTemp.get(x)).toString());
wireSize1.setText(((Double)secGaTemp.get(x)).toString());
secOhm1.setText (((Double)secOhmsTemp.get(x)).toString());
//secOhm1.setText(String.format("%6.3f",((secOhmsTemp.get(x))).toString()));
cmPerAmp1.setText(((Double)secCmTemp.get(x)).toString());
} else if (choice.intValue() > secTurnsTemp.size()) {
secTurns1.setText("");
wireSize1.setText("");
cmPerAmp1.setText("");
secOhm1.setText("");
}

this is the code in ed
private JTextField secOhm1;
private JComboBox jComboBox3;
private JPanel secWindingDetails;


private Vector secTurnsTemp;
private Vector secGaTemp;
private Vector secOhmsTemp;
private Vector secCmTemp;
a partial declarations list in ed
hope this is enough code

olly
terry oliver
Greenhorn

Joined: Jan 04, 2008
Posts: 22
found my error see below thanks for all your help

secOhm1.setText(String.format("%6.3f",((secOhmsTemp.get(x)))));

olly
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: decimal place formatting JtextField
 
Similar Threads
enter only numeric
JTextField and decimal number
How to verify input in the JTextField?
Double only accurate to 18 significant figures?
NumberFormat, Currency, JTextField