Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

g.drawString is not printing the correct value in Jpanel.

g.drawString is not printing the correct value in Jpanel.

The program is few thousand lines long. So I am posting a snippet where the error occurs

String tmpStg=new String(Integer.toString(val3));

System.out.format("%d %d %s %s\n",indexOfBlock,indexOfBlock1,String.valueOf(indexOfBlock1),tmpStg);

g.drawString(String.valueOf(indexOfBlock1),thsXPosWithBorder+10,thsYPosWithBorder);

System.out.format("%d %d %d\n",indexOfBlock,indexOfBlock1,val3);

Output of this section of the code is

0 8 8 8

0 8 8

While the values in print statement are correct. The value printed on the jpanel using g.drawString

is not correct. The g.drawString method prints 0 in the graphics panel instead of 8. The value in indexOfBlock1

is 8 and value in indexOfBlock is 0. Value in val3 is also same as value in indexOfBlock1. But if

I print it through g.drawString then it shows value as 0.

Comments
Post Details
Added on Apr 12 2019
0 comments
203 views