Extract current text from JavaTextField

S

stevenruiz

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top