Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

update JLabel and JTextArea in background thread  RSS feed

 
Andy Wong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some complicated components like JTable or JList, I understand that I have to follow the MVC pattern to first update the data in model in order to have change effective.
But for those simply components like JLabel and JTextArea, is there any model behind? or do necessary to follow the same routine like JTable? Can I just update the content (the text property) in a background thread? Please advise?
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to change your name to fit the Naming policy (first and last name).
As for your question, JLabel doesn't use one so you can just setText("whatever"). JTextArea also behaves the same way, but it has more options for things like line wrapping and columns. Just go look it up in the Java docs and look at Sun's tutorial here.
Technically, you could say that the String you setwith setText is the model and the TextArea is the controller and viewer.
Hope this helps
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chris!

Actually for all the things that inherit from JTextComponent (like JTextArea) the Model is called the Document, so they really do have a Model... The only Swing components I can think of that aren't pure MVC are JLabel (like you mentioned), JSeparator, and those components that are made just to hold other components, like JPanel, JFrame, etc.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!