Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with spacing of text in JTextArea

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use a monospaced font
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah.. can you expand on that a little, I know nothing about how to use fonts.

Thanks for any help
 
Campbell Ritchie
Sheriff
Posts: 48445
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 750
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic