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 6 of 6

Thread: Setting tab size for JEditorPane

  1. #1
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Setting tab size for JEditorPane

    Is there a way to set the tab size (either in pixels or space units) for JEditorPane's? I'm using an HTMLDocument, so it doesn't matter if the tab size is set via css styling or from the program itself. If it is indeed being set from a css style sheet, it will likely need to apply to a <pre> tag since that's what I'm using.

    What i'm trying to create is a colored syntax highlighting text component using the HTMLEditorKit to facilitate coloring (JTextArea unfortunately requires all text to have the same font/style, not suitable for this application). However, the default tab size for JEditorPane/HTMLDocuments is ~20 spaces, which is way too large. I would also prefer to not force all tabs to be converted into spaces.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Setting tab size for JEditorPane

    Quote Originally Posted by helloworld922 View Post
    However, the default tab size for JEditorPane/HTMLDocuments is ~20 spaces, which is way too large. I would also prefer to not force all tabs to be converted into spaces.
    Strange. For me the tab spacing is much less, more like 8 spaces to start a line and 3 in mid-line, but it is also context dependent to allow for lining up of tabbed elements so tab-delim formats line up properly. I don't know of a way to set it off the top of my head. You may really have to get into the nitty gritty of the backend of a JEditorPane to do so programmatically. Don't think there is a way via css - at least a way that is respected by the limited css capability of a JEditorPane.
    Last edited by copeg; September 5th, 2010 at 11:30 AM.

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Setting tab size for JEditorPane

    You need to set the tab stops to the document, not the view.

    Related classes/methods:
    DefaultStyledDocument (Java Platform SE 6)
    StyleConstants (Java Platform SE 6)
    TabSet (Java Platform SE 6)

    I haven't done this myself but I'm willing to try to help if you encounter a problem in implementing this. Just post a SSCCE and indicate what's not right with it.

    luck, db
    Last edited by Darryl.Burke; September 6th, 2010 at 01:16 AM. Reason: Added underline to the links. Something really should be done to make links noticeable

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Setting tab size for JEditorPane

    I found an article concerning a similar topic (the solution is the last post, with an in-depth discussion at the link in the second to last post):

    how can I change the Tab size of JTextPane ?

    It's not a JEditorPane, but rather a JTextPane and I don't think this uses the HTMLEditorKit, either. However, I will try to figure out these little issues when I'm more awake

  5. #5
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Setting tab size for JEditorPane

    JTextPane extends JEditorPane and can have a StyledDocument. And as far as I can make out, it's the document, not the editor kit, that is to be manipulated.

    db

  6. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Setting tab size for JEditorPane

    Quote Originally Posted by Example Snippet
    textPane.setParagraphAttributes(def,true);
    This is actually a JTextPane method. I don't imagine it would be too hard to write an equivalent for JEditorPane, though. Also, JTextPane has access to the HTMLEditorKit, too so I think it makes sense for my application to switch over to using a JTextPane (I picked JEditorPane rather arbitrarily)
    Last edited by helloworld922; September 6th, 2010 at 11:37 AM.

Similar Threads

  1. Setting JFrame maximum size that pack() can not violate
    By Javabeginner in forum AWT / Java Swing
    Replies: 3
    Last Post: September 3rd, 2010, 05:53 AM
  2. Limit File Size or Request Size
    By tarek.mostafa in forum Java Servlet
    Replies: 3
    Last Post: June 12th, 2010, 04:28 PM
  3. Limit File Size or Request Size
    By tarek.mostafa in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: June 11th, 2010, 07:21 AM
  4. refreshing JEditorPane
    By nasi in forum AWT / Java Swing
    Replies: 9
    Last Post: April 9th, 2010, 04:01 AM
  5. writing to JEditorPane
    By nasi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 8th, 2010, 09:23 PM