Results 1 to 13 of 13
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Set parts of text to italics

  1. #1
    Blondedude092 is offline Member
    Join Date
    Sep 2012
    Posts
    16
    Rep Power
    0

    Default Set parts of text to italics

    How would I set only a part of the text as italics?

    Example: Here is some text...

  2. #2
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default Re: Set parts of text to italics

    Step 1, read the text or parse it or tokenize it. Recognize the part that you want, then format it.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Set parts of text to italics

    Your question is impossible to answer without some context. What exactly are you talking about? A Swing GUI? An Android application? Text in an RTF file? Please tell us the details and show some code.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Set parts of text to italics

    Quote Originally Posted by bigsonny View Post
    Step 1, read the text or parse it or tokenize it. Recognize the part that you want, then format it.
    And I have no idea what you're suggesting. Format it how?

  5. #5
    Blondedude092 is offline Member
    Join Date
    Sep 2012
    Posts
    16
    Rep Power
    0

    Default Re: Set parts of text to italics

    Swing GUI. Keep in mind I know little Java.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Set parts of text to italics

    So, then let me get this straight, you want to display text in a Swing GUI where a selected section of the text is italicized, correct?

    If so, the easy way to do this is to use HTML markup language to change the font, but note that this won't work in all situations, and I believe for instance that it won't work on a JTextArea for instance. If you want a textarea type of text component, then you may wish to look into using a JTextPane or a JEditorPane. The tutorials will show you how to use them and their styled documents.

  7. #7
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default Re: Set parts of text to italics

    Quote Originally Posted by Fubarable View Post
    And I have no idea what you're suggesting. Format it how?
    I was skipping some parts but eventually, he'd have to use swing. That's the only way that I know. As far as I know, printing to the console using System.out does not allow that.

  8. #8
    Blondedude092 is offline Member
    Join Date
    Sep 2012
    Posts
    16
    Rep Power
    0

    Default Re: Set parts of text to italics

    I am using a JTextFeild, I want only a part of the text to be italicised

  9. #9
    bigsonny is offline Senior Member
    Join Date
    Nov 2010
    Posts
    164
    Rep Power
    4

    Default Re: Set parts of text to italics

    Actually AWT, SWT among others could be used...For the how...Ask the experts. lol.

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

    Default Re: Set parts of text to italics

    There are many ways how this can be done:

    1) read the API for the Font class; it has italics versions of every possible font;
    2) alternatively, use <html> tags for text components (e.g. JLabels);
    3) use shearing on your Graphics device.
    4) etc.?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Set parts of text to italics

    Quote Originally Posted by Blondedude092 View Post
    I am using a JTextFeild, I want only a part of the text to be italicised
    JTextField does not support multiple fonts or attributes. You've already been told which text components are suitable for your requirement.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  12. #12
    Blondedude092 is offline Member
    Join Date
    Sep 2012
    Posts
    16
    Rep Power
    0

    Default Re: Set parts of text to italics

    ok, but this still don't give me an answer as to how to accomplish what i'm trying to do with any other component. I'm looking for a solution, not all the things that are wrong what i'm doing.

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Set parts of text to italics

    Quote Originally Posted by Blondedude092 View Post
    ok, but this still don't give me an answer as to how to accomplish what i'm trying to do with any other component. I'm looking for a solution, not all the things that are wrong what i'm doing.
    Again:

    ... If you want a textarea (or JTextField) type of text component, then you may wish to look into using a JTextPane or a JEditorPane. The tutorials will show you how to use them and their styled documents.
    DarrylBurke likes this.

Similar Threads

  1. Pattern for matching parts of url
    By joan.balaguero in forum New To Java
    Replies: 1
    Last Post: 05-10-2012, 02:52 AM
  2. Replies: 0
    Last Post: 09-12-2011, 01:06 PM
  3. several threads for different parts
    By Itun in forum AWT / Swing
    Replies: 2
    Last Post: 03-20-2011, 11:18 PM
  4. need help with few parts in java program please!
    By fezman1337 in forum JCreator
    Replies: 1
    Last Post: 11-22-2010, 05:26 PM
  5. Replies: 2
    Last Post: 02-18-2008, 04:24 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
  •