The Artima Developer Community
Sponsored Link

Java Answers Forum
Problem with text control

3 replies on 1 page. Most recent reply: Dec 17, 2004 3:49 AM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
vipin.singh

Posts: 3
Nickname: vips
Registered: Sep, 2004

Problem with text control Posted: Sep 26, 2004 4:32 PM
Reply to this message Reply
Advertisement
Hi,
I am having a text control in a pannel. Every time I type in a text box I have to press enter or tab and then click on Submit button, then only the value from textbox is taken. If I enter some value in the textbox and click on Submit Button by mouse, the new value in textbox is not taken. Suppose in text box I have value as Vinay, and I change the value to Vipin and click on Submit button by mouse, still the old value in textbox ("Vinay") is taken. How can I allow the value "Vipin" to be taken, even if I click on Submit button by mouse. Thanks for the help in advance.
Regards,
Vipin.


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: Problem with text control Posted: Sep 28, 2004 4:34 AM
Reply to this message Reply
> Hi,
> I am having a text control in a pannel. Every time I type
> in a text box I have to press enter or tab and then click
> on Submit button, then only the value from textbox is
> taken. If I enter some value in the textbox and click on
> Submit Button by mouse, the new value in textbox is not
> taken. Suppose in text box I have value as Vinay, and I
> change the value to Vipin and click on Submit button by
> mouse, still the old value in textbox ("Vinay") is taken.
> How can I allow the value "Vipin" to be taken, even if I
> click on Submit button by mouse. Thanks for the help in
> advance.
> Regards,
> Vipin.


1. Add a key listener to the text field.
2. In the class that implements KeyListener, have something along the following lines...

public void keyReleased(KeyEvent e){
	    
        JTextField source = (JTextField)e.getSource();
        String textToSearch = source.getText();
.
.
.
.

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Problem with text control Posted: Dec 17, 2004 3:48 AM
Reply to this message Reply

private void jbInit() throws Exception
{
this.getContentPane().setLayout(null);
this.setSize(new Dimension(400, 300));
jTextArea1.setText("Test");
jTextArea1.setBounds(new Rectangle(40, 40, 225, 60));
jTextArea1.setForeground(Color.red);
jButton1.setText("jButton1");
jButton1.setBounds(new Rectangle(95, 175, 73, 22));
jButton1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jButton1_actionPerformed(e);
}
});
this.getContentPane().add(jButton1, null);
this.getContentPane().add(jTextArea1, null);
}

private void jButton1_actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null, jTextArea1.getText());
}


Its a part of code and it works fine...

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: Problem with text control Posted: Dec 17, 2004 3:49 AM
Reply to this message Reply
  private void jbInit() throws Exception
  {
    this.getContentPane().setLayout(null);
    this.setSize(new Dimension(400, 300));
    jTextArea1.setText("Test");
    jTextArea1.setBounds(new Rectangle(40, 40, 225, 60));
    jTextArea1.setForeground(Color.red);
    jButton1.setText("jButton1");
    jButton1.setBounds(new Rectangle(95, 175, 73, 22));
    jButton1.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          jButton1_actionPerformed(e);
        }
      });
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jTextArea1, null);
  }
 
  private void jButton1_actionPerformed(ActionEvent e)
  {
    JOptionPane.showMessageDialog(null, jTextArea1.getText());
  }


Its a part of code and it works fine...

Flat View: This topic has 3 replies on 1 page
Topic: an interesting JTextField question - please help! Previous Topic   Next Topic Topic: creating a reset button

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use