Link to home
Start Free TrialLog in
Avatar of andyw27
andyw27

asked on

Using setText function - mixing text and variables

I'm using the setText function.

What the synatx for mixing variables and text ?

Is it something to what used in c printf("Variable1 is %d", variable1);

Many thanks.
Avatar of ForceRs
ForceRs

JLabel myLabel = new JLabel("Test");
myLabel.setText("Var1 value: " + myVar1.toString() + ", Var2 value: " +  myVar2.toString());
ASKER CERTIFIED SOLUTION
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andyw27

ASKER


I'ved tried the above code but get:

int cannot be dereferenced error ?

Any idea's?
Avatar of andyw27

ASKER


Its okay I fixed it now, it did'nt need the toString method.
in java you dont need to string convertion to write int variables to screen.