Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By quad64bit

Thread: Formatting output string in Java GUI?

  1. #1
    dojob is offline Member
    Join Date
    Jul 2013
    Posts
    52
    Rep Power
    0

    Default Formatting output string in Java GUI?

    I am trying to convert a displaying calendar code from console output to GUI output.
    But it seems that i can't align it perfectly as in the console.

    Even if i use the same spacing to replace, it does not align correctly as it suppose to.
    The picture shows that the GUI output is not align perfectly.
    How to output it as perfect as the console output?

    Another question I would like to ask is is there any way to replace this code in Java GUI output?
    Java Code:
    System.out.printf("%4d", i);
    Following is output for console:


    Following is output for GUI
    Attached Thumbnails Attached Thumbnails Formatting output string in Java GUI?-image.jpg  

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Formatting output string in Java GUI?

    It's probably because your terminal uses a fixed width font and your gui doesn't. If you don't know what the difference is - look it up, it's valuable to know the difference. Try something like courier or monaco.
    dojob likes this.

  3. #3
    dojob is offline Member
    Join Date
    Jul 2013
    Posts
    52
    Rep Power
    0

    Default Re: Formatting output string in Java GUI?

    Thanks. Now i know that it suppose to use fixed width font

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Formatting output string in Java GUI?

    Quote Originally Posted by dojob View Post
    Another question I would like to ask is is there any way to replace this code in Java GUI output?
    Read the API for String#format(...)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Formatting Output
    By Rahim2312 in forum New To Java
    Replies: 18
    Last Post: 05-04-2012, 09:45 AM
  2. Help with formatting output
    By John Lord in forum New To Java
    Replies: 1
    Last Post: 10-31-2010, 12:10 PM
  3. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  4. formatting numbers in output
    By andy3 in forum New To Java
    Replies: 3
    Last Post: 05-27-2010, 06:43 PM
  5. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM

Posting Permissions

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