Extract current text from JavaTextField
Hello All,
I have a question regarding the JTextField. I have the below code
which is initiated when the user clicks on a start button from the
interface:
private JButton getStartButton() {
if (startButton == null) {
startButton = new JButton();
startButton.setBounds(new Rectangle(283, 66, 71, 22));
startButton.setText("Start");
startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
sStartPushed = true;
System.out.println(jTextField.getText());
System.out.println("actionPerformed()"); // TODO Auto-generated
Event stub
}
});
}
return startButton;
}
Inside of the action listener for this button, it prints out the text
for the textField associated with the button. Unfortunately, the text
it returns is not the current text that was just typed inside of it.
How do I get the current text? I have also tried
jTextField.getSelectedText() which does not get the current value
inside of the textField. Any comments or suggestions would be
appreciated.