Results 1 to 6 of 6
  1. #1
    hill0093 is offline Member
    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0

    Default Bold and regular equally spaced font in an output String

    I have a little program that I wrote a few years ago that
    picks numbers out of a text file written by an
    old Fortran program and writes a text file read by MS Notepad.
    It makes a String for each line and uses BufferedOutputStream().
    I previously never worried about what font I was using.
    But now I must choose an equally spaced font, and some numbers in
    the String for a line must be Bold and the rest Regular font.
    How do I set the type of every substring when appending for this String?
    Or do I have to use a different approach?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Bold and regular equally spaced font in an output String

    You could use a styled text area (JTextArea or JEditorPane). See Using Text Components (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)

    [Edit] That's for onscreen display. I don't think notepad displays styled text. If the output is going to use some other format then you would have to output whatever format it expects. Web browsers will display text in HTML format which is simple in as much as it is just plain text.
    Last edited by pbrockway2; 04-27-2013 at 05:05 PM.

  3. #3
    hill0093 is offline Member
    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0

    Default Re: Bold and regular equally spaced font in an output String

    Thanks, I checked, and Notepad doesn't use two different fonts at the same display.
    MS Wordpad or MS Word will do, but I need both Bold and Regular in the same file.
    And of course the output doesn't have to be a String.
    Last edited by hill0093; 04-27-2013 at 05:43 PM.

  4. #4
    hill0093 is offline Member
    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0

    Default Re: Bold and regular equally spaced font in an output String

    Thanks, I checked, and Notepad doesn't use two different fonts at the same display.
    MS Wordpad or MS Word will do, but I need both Bold and Regular in the same file.
    And of course the output doesn't have to be a String.

    It looks like java doesn't have a good way to
    get Bold and Regular together into a file.
    I am surprised.
    I will just keep on changing by manual selection and
    changing font on parts of the information I have
    pasted into MS Word into Bold.
    Unless someone shows me a way of putting it into the file.

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

    Default Re: Bold and regular equally spaced font in an output String

    Quote Originally Posted by hill0093 View Post
    It looks like java doesn't have a good way to
    get Bold and Regular together into a file.
    That's not it; each and every editor, file viewer etc. has its own proprietary way of marking a certain portion of the text for a font change. The easiest (or one of the easiest) ways of handling this are html tags. but MS-word doesn't use it; Java can output any byte sequence but the sequence has to match what the 'other side' is expecting. Files themselves don't have any notion of font changes, files are sequences of bytes; it's how you interpret those sequences ...

    kind regards,

    Jos

    ps. there's an Apache project that can handle MS-word formats of text. Google is your friend here.
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Bold and regular equally spaced font in an output String

    Apache-POI, the project metioned above, has never actually released the Word part...it's flaky, to say the least.

    Java comes with an RTFEditorKit, which will allow you to write out the Document from a Swing Text class as an RTF file.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. how to print bold output
    By jihad in forum New To Java
    Replies: 1
    Last Post: 01-16-2012, 09:27 PM
  2. Bold font in JTabbedpane in Nimbus L&F
    By sponarun in forum AWT / Swing
    Replies: 0
    Last Post: 02-28-2011, 07:58 AM
  3. TODO in bold font in Text Editor
    By SSG_JJV in forum Eclipse
    Replies: 1
    Last Post: 03-25-2009, 11:42 PM
  4. String Bold
    By Xystus777 in forum New To Java
    Replies: 4
    Last Post: 01-20-2009, 07:59 AM
  5. Returning a string (Partly Bold)
    By TampaTechGuy in forum New To Java
    Replies: 3
    Last Post: 02-03-2008, 10:54 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
  •