• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTextArea update, URGENT HELP PLS

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I have a frame with 2 JTextAreas one on the left and one on the right.
they both get initialized in the constructor of the JFrame. I am trying to load a txt file into the left side, but everytime it only works for the first load and after that i get a blank screen. is there like an update or repaint i should use? thx in advance.

public void actionPerformed(ActionEvent event)

{

String eventStr = event.getActionCommand();
JComponent c = (JComponent) event.getSource ();

if(eventStr.equals("Open"))
{

FileDialog fd = new FileDialog(Display.this);
int status = chooser.showOpenDialog(Display.this);

if(status == JFileChooser.APPROVE_OPTION)
{
File f = chooser.getSelectedFile();
//System.out.println(getContents(f));
left.setText(getContents(f));
//more stuff .....

}
}
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
at a guess. ( Im still a novice ) I would imagine you need to call the revalidate() or validate() method for that panel. Ive never had a problem with setText not updating on the fly.
[ May 14, 2006: Message edited by: Al Hollis ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> is there like an update or repaint i should use?

a call to setText(...) will automatically trigger a repaint().

when you say it works on the first load, then not after that, is the first
load in the constructor?

if it is, you may have duplicate declarations of your textArea
e.g.


in the above, the textArea in the constructor is a local variable - it is
the one added to the gui and the one you see on the screen.

the other one is what actionPerformed is working with - it is not visible anywhere.

to fix, either remove the textArea line from the constructor, or
change (in the constructor)
JTextArea ta = new JTextArea(...);
to
ta = new JTextArea(...);
 
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic