listener for JFormattedTextField

Hi. I'm trying to do a simple thing. I have a JFormattedTextField and when You enter some value in that field and press Enter I'd like the testLabel to display that value. My code doesn't work, what am I doing wrong?

package trial;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Dimension;

import java.awt.GridLayout;

import java.beans.PropertyChangeEvent;

import java.beans.PropertyChangeListener;

import java.beans.PropertyChangeSupport;

import javax.swing.JFormattedTextField;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.event.ChangeEvent;

publicclass TrialMainimplements PropertyChangeListener{

JLabel testLabel =new JLabel();

JLabel command =new JLabel("Enter some text below:");

JFormattedTextField enterText =new JFormattedTextField();

public TrialMain(){

JFrame frm =new JFrame();

frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel p =new JPanel(new GridLayout(5, 1) );

p.setOpaque(true);

p.setPreferredSize(new Dimension(200, 200) );

p.setBackground( Color.GREEN );

frm.setContentPane(p);

p.add(testLabel);

p.add(command);

p.add(enterText);

enterText.addPropertyChangeListener(this);

frm.pack();

frm.setVisible(true);

}

publicstaticvoid main(String[] args){

new TrialMain();

}

publicvoid propertyChange(PropertyChangeEvent evt){

Object source = evt.getSource();

if(source == enterText){

testLabel.setText(enterText.getText());

}

}

}

[3122 byte] By [bobens_83a] at [2007-11-27 3:45:31]
# 1
I'm no Swing guru (if you posted in the Swing forum you would have gotten better responses) but I think you want an ActionListener not a PropertyChangeListener.
floundera at 2007-7-12 8:49:14 > top of Java-index,Java Essentials,New To Java...
# 2
I haven't looked all that closely but according to http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html it should beenterText.addPropertyChangeListener("value", this);
pbrockway2a at 2007-7-12 8:49:14 > top of Java-index,Java Essentials,New To Java...