Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Scrollbars and Textareas  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, for my chess program, I want to be able to show the moves played, inside a box somewhere in the JFrame.
I would like the box to be a fixed size, so that a scrollbar on the side of the box lets you see all the moves.

However, I don't think its a textarea I want, I just want the text displayed to be read only.

Can anyone point me in the right direction?

Thanks very much
[ May 06, 2006: Message edited by: colin shuker ]
 
Campbell Ritchie
Sheriff
Posts: 55333
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably do want a JTextArea. You can set its editability with the setEditable() method.
If you want it to scroll, add a JScrollPane with the text area passed to its constructor.
Use the append() method to add your latest move to the end of the text area.

CR
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

I had to sort my GUI out using a GridbagLayout first,
then I created a JTextArea jta, set the setEditable() method with false.
Then I put this into the constructor of JScrollPane using...

And it works great.
I'm surprised how easy it was to get it to work...
I've tested it using insert(...,...) method of JTextArea, and its looking good.

Thanks for your help
 
Campbell Ritchie
Sheriff
Posts: 55333
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a pleasure.
CR
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!