Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

decimal place formatting JtextField

 
terry oliver
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried the toString method of vector before trying to String.format?
 
terry oliver
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i did try that and the error was vector cannot be applied to string.


olly
 
Nickolas Case
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code? Are you tring to format in the JTextField or before placing the value in the JTextField?
 
terry oliver
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
found my error see below thanks for all your help

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

olly
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic