• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting Value at Index0 of editable combo box  RSS feed

 
Heather Marie
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How do I simply set index 0 of a combo box. See code below. I've read a file, created an array (with doubles) and now I can't seem to "reset" the first element in an editable combo box (yrsdropbox) to display a value read from the file. Obviously, what I'm doing is not working. Please help.
Heather

public void rfile(){
try{
BufferedReader in = new BufferedReader(new FileReader("c:\\javastuff\\mortgage.txt"));
int counter = 0;
double[] data = new double[3];
for(int x = 0; x < data.length; x++)
{
data[x] = Double.parseDouble(in.readLine());
}
in.close(); //close the reader
double loan = data[0];
double terms = data[1];
double rate = data[3];
double interest = (0.0535/12); //How do I get the rate to go to the appropriately decimal place?
double payment = (loan*Math.pow(1+interest,terms)*interest)/(Math.pow(1+interest,terms)-1);
paymnt.setText(currency.format(payment));
yrsdropbox.setSelectedIndex(terms);
} catch (Exception e) {
System.out.println("File Error!");
e.printStackTrace();
}
}

The error I'm geting has to do with trying to use setSelectedIndex and a double. See the error below:
___________________________________________________

GuiMortgage.java [181:1] setSelectedIndex(int) in javax.swing.JComboBox cannot be applied to (double)
yrsdropbox.setSelectedIndex(terms);
^
1 error
Errors compiling GuiMortgage.


 
Mark Van Tuyl
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setSelectedIndex() requires a single paramter of an int. You're passing it a double.

Casting it to an int will work:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!