-
September 11th, 2006, 06:51 AM
#1
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
-
September 11th, 2006, 07:02 AM
#2
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.
-
February 1st, 2007, 04:34 AM
#3
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.
-
February 1st, 2007, 07:14 AM
#4
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
-
February 1st, 2007, 07:22 AM
#5
Re: Tab Spacing with Code
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.
-
February 1st, 2007, 07:40 AM
#6
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
-
February 1st, 2007, 07:46 AM
#7
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
-
February 1st, 2007, 07:51 AM
#8
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.
-
February 1st, 2007, 07:58 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|