• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextArea update, URGENT HELP PLS

 
Araad Izadkhah
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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 .....

}
}
 
Al Hollis
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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 ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • 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(...);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!