Results 1 to 4 of 4

Thread: [RESOLVED] Java Column Alignment ARGHHHHH!!!!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    23

    Resolved [RESOLVED] Java Column Alignment ARGHHHHH!!!!!

    Hey guys got a Java question for you.

    I have finished coding (well thought I had finished coding) a program in java but the only problem is that it is giving me the correct input but it isn't in the columns properly.. an example picture has been attached to this post.

    As you can see in the picture the column headings do not line up properly with the results. This is because of the word length of the results. I want to know how I can make everything move into pretty columns without having to shorten all the names (as that is not going to happen in the real world).

    My code for printing the headings (Code, Brand, Name, Price) is:

    public void listProducts() {

    System.out.printf("%-8s %-8s %8s %8s \n", "Code", "Brand", "Name", "Price");
    for (int index = 0; index < productList.size(); index++)
    printProductDetails(productList.get(index));
    }
    My code for printing the details is this:

    public static void printProductDetails(Product product) {
    System.out.printf("%-8s %-8s %8s %8s \n", product.getCode(), product.getBrand(), product.getName(), product.getPrice(), '\n');
    }
    Attached Images Attached Images  

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Java Column Alignment ARGHHHHH!!!!!

    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    23

    Re: Java Column Alignment ARGHHHHH!!!!!

    Thanks buddy, that's exactly what I needed

    This issue has been resolved, I am lined up nicely now!

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Java Column Alignment ARGHHHHH!!!!!

    Glad to hear that. Don't forget to mark the thread resolved from the "Thread Tools" menu
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

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



Click Here to Expand Forum to Full Width