Results 1 to 6 of 6
  1. #1
    sfe23's Avatar
    sfe23 is offline Member
    Join Date
    Feb 2009
    Posts
    42
    Rep Power
    0

    Default How to align the output on console?

    Hi,
    Can anyone tells me what method I should use to align the output?
    I am searching but can't find anything.

    thank you :)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You may wish to describe your problem in greater detail as the answer will depend upon the requirements. Is this a Swing app with output in a JTextField? A console app?

    If the latter, then you might want to look at System.out.printf(...) method or String.format(...). They both do the same thing. You'll have to read the tutorial and API several times to "get" this (I know that I had to on the first go-around), but it's eventually worthwhile reading.

  3. #3
    sfe23's Avatar
    sfe23 is offline Member
    Join Date
    Feb 2009
    Posts
    42
    Rep Power
    0

    Default

    Thanks for your prompt answer.
    I just realized how vague my question was! Sorry about that.
    I am printing(outputing) from a string linkedList both in a console and in a text file.
    I need to output each String(word), with different lengths, along with a corresponding #
    so my output now looks like:
    firstWord 1
    anotherWord 2
    word 3

    but I want it to be aligned:
    firstWord 1
    anotherWord 2
    word 3

    could I use tab (\t) somehow or do I need to use a method?
    tell me which tutorials I need to read for this and I'd be willing to do that , thanks :)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    sfe23's Avatar
    sfe23 is offline Member
    Join Date
    Feb 2009
    Posts
    42
    Rep Power
    0

    Default

    I have looked at both links but they talk about formatting numbers.
    I didn't see an example of what I want there :(
    I need to format the output sting by adding a tab or 2 after each string or something like that!

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    They format Strings too. Read them again. You use %XXs where XX is some number for Strings. Again, read again.

Similar Threads

  1. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-26-2009, 12:44 AM
  2. Right Align columns in JTable
    By Laura Warren in forum New To Java
    Replies: 2
    Last Post: 12-18-2008, 10:01 PM
  3. Java Swing class capturing output to the console
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-12-2008, 12:24 PM
  4. JTextArea - text align
    By bradder in forum AWT / Swing
    Replies: 1
    Last Post: 11-29-2007, 08:08 PM
  5. Replies: 1
    Last Post: 07-24-2007, 03:02 AM

Posting Permissions

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