Extract current text from JavaTextField

Discussion in 'Java' started by stevenruiz@gmail.com, May 5, 2008.

  1. Guest

    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.
    , May 5, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manu
    Replies:
    1
    Views:
    6,075
    Natty Gur
    Jul 20, 2003
  2. Matthew Heidemann
    Replies:
    14
    Views:
    231
    eT Ma
    Mar 22, 2011
  3. Replies:
    3
    Views:
    168
  4. Jack
    Replies:
    3
    Views:
    582
    Tad J McClellan
    Dec 22, 2008
  5. Mladen
    Replies:
    5
    Views:
    158
    Peter Scott
    Feb 22, 2011
Loading...

Share This Page