explain a code for swing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kalar
    New Member
    • Aug 2007
    • 82

    explain a code for swing

    I want to draw a text on a JPanel.I know about method drawString but i can't make it work. Then i found a code in the Internet :

    learning java

    but i can't understand how works? If i put in str_x and str_y , 0 and 0 it doesn't prints me anything. If i leave them as it is it prints me the string but only in the center of x-axis, look

    if i put something else as example drawString("hi" , 20,20) still doesn't print anything
    thanks in advance!
  • kalar
    New Member
    • Aug 2007
    • 82

    #2
    because i can't edit my post:
    i have these problmes and with other draw... methods. So i guess my mistake is in the way that i get the dimensions? What should i do in order to work?

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by kalar
      because i can't edit my post:
      i have these problmes and with other draw... methods. So i guess my mistake is in the way that i get the dimensions? What should i do in order to work?
      For starters: if you want to print a String starting at position x, y, the left most
      position will be x and the *baseline* of the String will be at position y, i.e. only
      the descenders of the characters will be below (i.e. a larger y coordinate) that
      baseline. If you want to print a String at position 0,0 most if not all of the String
      won't be visible (above the visible area).

      Another remark: if you print characters (a String) in red on a red background
      you won't see them of course; are you sure you have set the foreground color
      to something else before you draw the String?

      kind regards,

      Jos

      Comment

      • kalar
        New Member
        • Aug 2007
        • 82

        #4
        Thank you Jos i understand how works,(i put something like 0,10 and i saw the letters on the screen)

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by kalar
          Thank you Jos i understand how works,(i put something like 0,10 and i saw the letters on the screen)
          Good; moral of the story: always read the darn^H^H^H^H fine API documentation
          before you even *think* of typing something in front of your computer. It can only
          lead to misery; proof: see the current state of ICT in the world ;-)

          kind regards,

          Jos

          Comment

          Working...