Find the answer to your Linux question:
Results 1 to 3 of 3
Umm...okay. I have just come across something very weird within Java, and I'm interested to see if anyone knows a way to fix this. I have the following bit of ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252

    Java String Lengths [SOLVED]


    Umm...okay. I have just come across something very weird within Java, and I'm interested to see if anyone knows a way to fix this.

    I have the following bit of code in a GUI application that I'm writing:

    Code:
    if(currentCode.length() > 11)
            tab_string = "\t";
    else
            tab_string = "\t\t";
    My idea here is to line up things into two columns of data. This works almost universally, except in 2 examples:

    http://soori.netfirms.com/example/stringlength1.png
    http://soori.netfirms.com/example/stringlength2.png

    In both of those, there is an example where the arrow isn't lined up. However, there are also other examples (where the code is actually LONGER than the one not displaying properly) that have the right arros spacing.

    Can anyone tell me a good way to get around this? I can't figure out what's wrong, since it's working in 99% of the examples.

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2005
    Location
    Hell
    Posts
    514
    It's using a variable-length font, so number of characters doesn't determine the width. I don't know much about what you're doing, but can you somehow use fixed-width fonts or (better) put them into a table or something?

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Yay!

    Thanks. I admittedly know very little about Fonts, so I didn't even think of that.

    I changed it to Courier New, and it's working now. Thanks a bunch!!

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •