This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes problem with spacing of text in JTextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem with spacing of text in JTextArea" Watch "problem with spacing of text in JTextArea" New topic
Author

problem with spacing of text in JTextArea

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
I almost have my GUI working ok, but in my JTextArea, I have two columns:
One for whites moves, one for black.
I'm trying to space these out using spaces, but some letters take up more space than other letters.
The pic below should make it clear what my problem is.
pic of GUI
Blacks moved are not lined up neatly like white moves,
does anyone know of a way to fix this?

I'm not sure how to do pics on here, so I just stuck it on my website

Thanks

[ May 07, 2006: Message edited by: colin shuker ]
[ May 07, 2006: Message edited by: colin shuker ]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
use a monospaced font
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Ah.. can you expand on that a little, I know nothing about how to use fonts.

Thanks for any help
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Look up the setFont() method of JTextArea, and the Font class in the API specification.
There are five font families:
  • Serif
  • SansSerif
  • Monospaced
  • Dialog, and
  • Dialog Input.
  • Serif includes fonts like Time, SansSerif Arial, Monospaced (I think) Courier, and I am not sure about the other two.

    I don't know whether you can use the \t escape character to align your white and black columns. Nor whether you would find it easier to use two text areas in columns next to each other one for white's move the other for black.

    You can get attributes to add to your Font, as well as type, eg size, bold, italic, but not apparently underlining.

    CR
    colin shuker
    Ranch Hand

    Joined: Apr 11, 2005
    Posts: 744
    Thanks, I got that working fine now...
    There is one more thing (at least one ), but one for now...

    I have a vertical scrollbar on my JTextArea.
    I constructed the JScrollPane as:


    Where jta is a JTextArea.
    When I append a String to jta, it displays correctly in the scrollpane.
    However once the scrollpane fills up, and the blue slider on the scrollbar appears, it stays at the top... so that you can only read the first part of whats in the scrollpane, not the new info that is being added.

    I basically want the blue slider at the mottom of the scrollbar, so the user can see every new move that is displayed.

    Is this possible, I don't see any methods for it in JScrollPane class.
    Perhaps I have to get the Scroll bar with getVerticalScrollBar(),
    and then set the position on that object.

    Is that right?

    Thanks
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: problem with spacing of text in JTextArea
     
    Similar Threads
    Timer Trouble
    jTextfield problems
    JMenuItem text problem
    Scrollbars and Textareas
    Crazy Tables