Reputation: 1
I'm trying to set an int value using jLabel and the setText method. But of course setText wants a String. How do I get round this? I'll give you a snippet of the code:
int value = 1;
if (this.crit.getValue() == 1.0D)
{
value = 10 - ((int)(1.0D / this.crit.getValue()) + 1);
this.lblUnten.setText((int)(1.0D / this.crit.getValue())+"");
texts((int)(1.0D / this.crit.getValue()), this.lblUntenmitte);
}
if ((this.crit.getValue() < 1.0D))
{
value = 10 - ((int)(1.0D / this.crit.getValue()) + 1);
texts((int)(1.0D / this.crit.getValue()));
texts((int)(1.0D / this.crit.getValue()), this.lblUntenlinks);
}
if (this.crit.getValue() > 1.0D)
{
value = (int)this.crit.getValue() + 7;
this.lblUnten.setText((int)this.crit.getValue());
texts((int)this.crit.getValue(), this.lblUntenrechts);
}
this.scale.setSelection(value);
}
Upvotes: 0
Views: 1382
Reputation: 1
Convert your int into a String:
For example:
int yourNumber = 10;
yourJLabel.setText(String.valueOf(yourNumber));
Upvotes: 0
Reputation: 623
Well, that's actually fairly simple as you can just concatenate your int
with an empty string or call the toString()
method on your int
after having it wrapped in the Integer
class like below. It would look something like:
int yourNumber = 30;
yourLabel.setText(yourNumber + "");
or:
yourLabel.setText(new Integer(yourNumber).toString());
Upvotes: 1
Reputation: 608
Convert the int
to a String
. You can use String.valueOf(value)
:
int value = 10; // Your value
yourLabel.setText(String.valueOf(value));
Upvotes: 1