• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

decimal place formatting JtextField

 
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
 
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
 
Get off me! Here, read this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!