Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: need help alligning a table with \t

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default need help alligning a table with \t

    i need my table to look like this
    Description Units on Hand Price
    Jacket 12 59.9
    Designer Jeans 40 34.95
    Shirt 20 24.95


    my code says this
    public class RetailTest 
     {
    	public static void main(String[] aaa) 
    	{
    		RetailItem r1 = new RetailItem("Jacket",
    										12,
    										34.95
    										); //1
    		RetailItem r2 = new RetailItem("Designer Jeans",
    										40,
    										34.95
    										);   //2
    		RetailItem r3 = new RetailItem("Shirt",
    										20,
    										24.95
    										);
     
     
     
    		System.out.println("Description \tUnits On Hand \tPrice"); //4
    		System.out.println(r1.getDescription() +  "\t"  	
    							+ r1.getUnitsOnHand() + "\t" 
    							+ r1.getPrice() 
    							); // 5
     
     
    		System.out.println(r2.getDescription() +  " \t "  
    							+ r2.getUnitsOnHand() +  " \t "  
    							+ r2.getPrice() 
    							); //6
    		System.out.println(r3.getDescription() +  " \t "  
    							+ r3.getUnitsOnHand() +  " \t "  
    							+ r3.getPrice() 
    							); //7
    	}
     
     
    }

    what comes out is something like this/

    Description Units on Hand Price
    Jacket 12 59.9
    Designer Jeans 40 34.95
    Shirt 20 24.95

    how can i align them to look align i tried using the tab but it doesn't seem to be working. any help please. thank you


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: need help alligning a table with \t

    Where the tab stops are located depend on the program that is displaying the String with the tabs.
    Many Text viewing programs have a setting that allows you to specify what columns the tab stops are located in.
    The problem you are having looks like one of the Strings extends past the tab location and pushes the data to a further tab column than with a shorter String. If you can determine what columns the tab stops are located in, you should be able to add an extra tab character to the shorter String.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. 0-10Factorial table
    By my21 in forum Loops & Control Statements
    Replies: 11
    Last Post: April 17th, 2013, 12:21 AM
  2. Java Table
    By mija in forum AWT / Java Swing
    Replies: 4
    Last Post: September 16th, 2012, 02:50 PM
  3. Java Table
    By mija in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 16th, 2012, 09:35 AM
  4. Help me in alligning . GridBagLayout
    By fredsilvester93 in forum AWT / Java Swing
    Replies: 1
    Last Post: August 26th, 2012, 08:15 PM
  5. table comparison
    By awecode in forum JDBC & Databases
    Replies: 2
    Last Post: October 12th, 2010, 09:37 AM