• Post Reply Bookmark Topic Watch Topic
  • New Topic

Displaying text in GUI'S.  RSS feed

 
Douglas McAuley
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the best way to display uneditable text in a GUI?
I have tried using labels but come across problems trying to measure the size of the lines.
Regards. Douglas
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a lot of text and want it formatted, use a JTextArea, but do either a:
myTextArea.setEditable(false);
or
myTextArea.setEnabled(false);
Either will have the effect of making the component static (can't be edited by the user). You can do the same to a JTextField if you only have a small amount of text that you don't need to format.
Try both and see which you like the best (they will display differently, but neither can be edited).
 
Ban Bala
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above post is the best solution I have seen so far(please post if you find anything else). Setting the background colour to the TextArea's container will make it look like a label!
 
Brian Pipa
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also call a couple other things too to make it even better - without looking them up (I don't have my code with me) they are something like:
setFocusEnabled(false)
setSelectionEnabled(false)
and there was another to set the cursor in the text area not to show - I forget what call that was.
Try selecting text in you rtext area and see what happens
Brian
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!