CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2005
    Posts
    14

    Tab Spacing with Code

    Hi all,

    I'd like to know the code is for a Tab Space in java. Like \n for newline, what is it for a Tab space?

    Thanks in advance

  2. #2
    Join Date
    Apr 2001
    Location
    South Africa, Jo'burg
    Posts
    680

    Re: Tab Spacing with Code

    Hi,

    The escape character for a tab in java is \t
    Byron Tymvios

    Please use [ CODE ] and [/ CODE ] tags when posting code! See THIS on how to use code tags.

  3. #3
    Join Date
    Apr 2006
    Posts
    52

    Re: Tab Spacing with Code

    Hi. Well I've tried \t and it doesn't work, in java at least. Nor does \n. For the newline character I've managed to use System.getProperty("line.separator"), but I haven't managed to find one for the tab character. Does anyone know what else I can use for tab. Thanks in advance.

  4. #4
    Join Date
    Dec 2005
    Posts
    251

    Re: Tab Spacing with Code

    Well I've tried \t and it doesn't work, in java at least.
    You'll have to explain more why you think its doesn't work. How are you using it, what results are you getting. \t does indeed work in Java, its part of the language specification

  5. #5
    Join Date
    Apr 2006
    Posts
    52

    Re: Tab Spacing with Code

    Quote Originally Posted by gmrowe1075
    You'll have to explain more why you think its doesn't work. How are you using it, what results are you getting. \t does indeed work in Java, its part of the language specification
    Ok. I've tried something like this:
    Code:
    public String toString() 
    {
        String s = new String();
        s += "Name:  \t\t\t" + denConcert;// denConcert is a private string
        return s;
    }
    And it didn't put three tab characters as I'd expect. Oh, and I'm using this toString() function with a text field, like this:
    Code:
    private JTextField nume=new JTextField(5);
    nume.setText(ob.toString());
    where ob is an instance of the class that has the previous toString() method.
    Last edited by danutz_plusplus; February 1st, 2007 at 07:25 AM.

  6. #6
    Join Date
    Dec 2005
    Posts
    251

    Re: Tab Spacing with Code

    When I ran this:
    Code:
       public static void tabCheck()
       {
          String denConcert = "moved";
          String s1 = "Name:  \t\t\t" + denConcert;
          String s2 = "Name:  \t\t" + denConcert;
          String s3 = "Name:  \t" + denConcert;
          System.out.println(s1);
          System.out.println(s2);
          System.out.println(s3);
       }
    
       public static void main(String[] args)
       {
          tabCheck();;
       }
    I got this:
    Code:
    Name:  			moved
    Name:  		moved
    Name:  	moved

  7. #7
    Join Date
    Dec 2005
    Posts
    251

    Re: Tab Spacing with Code

    I just reread the last part of your post, the problem maybe with the way swing elements handle tabs, see here

  8. #8
    Join Date
    Apr 2006
    Posts
    52

    Re: Tab Spacing with Code

    Thanks for the link. But I think I found a way around my problem. By not using tabs. But I'll keep that link in mind. Thanks again.

  9. #9
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Tab Spacing with Code

    Incidentally, the Swing text components can handle all the basic HTML tags, so if you're planning much text formatting, such as fonts, colors, alignment, etc., it's often easier and quicker to use HTML text (optionally with CSS) than to mess with the Swing style/formatting classes.

    A programming language is like a natural, human language in that it favors certain methaphors, images, and ways of thinking...
    S. Papert
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

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

Featured