Results 1 to 12 of 12
  1. #1
    dougie1809 is offline Senior Member
    Join Date
    Nov 2011
    Posts
    116
    Rep Power
    0

    Default Tabular Expression

    Hi,

    In the toString method which returns all instance fields, I am trying to use the tabular expression '\t' between each of the fields. But when I test under main, it has no spaces? Sample code is below:
    Thanks

    Java Code:
    public String toString()
    	{
    		return title +"\t"+ genre +"\t"+ year;
    	}

  2. #2
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default Re: Tabular Expression

    What does your output look like?

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,534
    Blog Entries
    7
    Rep Power
    20

    Default Re: Tabular Expression

    Quote Originally Posted by dougie1809 View Post
    Hi,

    In the toString method which returns all instance fields, I am trying to use the tabular expression '\t' between each of the fields. But when I test under main, it has no spaces? Sample code is below:
    Thanks

    Java Code:
    public String toString()
    	{
    		return title +"\t"+ genre +"\t"+ year;
    	}
    Maybe that's because a tab character (\u0009) is not a space character (\u0020)?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default Re: Tabular Expression

    Quote Originally Posted by JosAH View Post
    Maybe that's because a tab character (\u0009) is not a space character (\u0020)?

    kind regards,

    Jos
    You're right. I was assuming they meant no spacing at all between the Strings was being seen. A tab is different from a space, but a tab no doubt creates "spacing".

  5. #5
    dougie1809 is offline Senior Member
    Join Date
    Nov 2011
    Posts
    116
    Rep Power
    0

    Default Re: Tabular Expression

    Sorry its not under main, the output is on a JList. The output returns three fields with no spaces.

    So what expression will I use then?
    Thanks

  6. #6
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default Re: Tabular Expression

    So the String returned from toString() is one of the items in your JList?

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,534
    Blog Entries
    7
    Rep Power
    20

    Default Re: Tabular Expression

    Quote Originally Posted by dougie1809 View Post
    Sorry its not under main, the output is on a JList. The output returns three fields with no spaces.

    So what expression will I use then?
    Thanks
    A JList is too stupid to display tabs the way you have in mind; think of a JTable instead; it has multiple columns (fields) per row.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    dougie1809 is offline Senior Member
    Join Date
    Nov 2011
    Posts
    116
    Rep Power
    0

    Default Re: Tabular Expression

    Well there are two Strings and an int which are returned from the toString().
    Iv'e tried the '\u0020' expression and it is a space. The other expression '\u0009' is nothing?

    Well Iv'e used JList because I am using a Stack structure to push and pop items in a list.
    I'd like to tab the three fields apart?
    Thanks

  9. #9
    dougie1809 is offline Senior Member
    Join Date
    Nov 2011
    Posts
    116
    Rep Power
    0

    Default Re: Tabular Expression

    Sorry just in case there's confusion, I want a tab space between the fields, not just a space. '\t' returns no tab spaces.
    Thanks

  10. #10
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default Re: Tabular Expression

    JosAH might be right, you may not be able to do what you are looking to do. You may have to manually put in the number of spaces comparable to a "\t"

  11. #11
    dougie1809 is offline Senior Member
    Join Date
    Nov 2011
    Posts
    116
    Rep Power
    0

    Default Re: Tabular Expression

    Oh right. Thanks guys for your help. Doing things manually isn't so bad :P

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,534
    Blog Entries
    7
    Rep Power
    20

    Default Re: Tabular Expression

    Quote Originally Posted by dougie1809 View Post
    Oh right. Thanks guys for your help. Doing things manually isn't so bad :P
    If you're using a monospaced font it might not be too bad, otherwise it's hell. Consider a JTable. btw a JList (or a JTextField) can't display tabs because they don't know where the tab stop positions are ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 2
    Last Post: 07-18-2011, 07:11 AM
  2. Regular Expression Help
    By niketanand in forum Advanced Java
    Replies: 1
    Last Post: 06-24-2011, 04:56 PM
  3. Big-oh expression help!
    By borgan in forum New To Java
    Replies: 2
    Last Post: 01-24-2011, 04:20 PM
  4. JSF expression inside another JSF expression
    By barbarabxl in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 05-21-2010, 03:03 PM
  5. Regarding Tabular data from .doc file
    By praveen83 in forum Advanced Java
    Replies: 10
    Last Post: 03-23-2010, 11:26 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
  •