Results 1 to 5 of 5
  1. #1
    DC%
    DC% is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default Problem's with JTextField

    Hey,

    I am having problem's getting input from a text field. If I enter some text in the field and use the following peice of code it always reads the field as being blank/null.

    Java Code:
    private void OK_actionPerformed(ActionEvent e) {
    		//screenname.setText("value");
    		
    		if(!screenname.getText().equals("")) {
    			basicChat.nameEntry(screenname.getText());
    			basicChat.guiStart();
    			
    		}
    		else {
    			InformationArea("Please enter a screen name to start");
    		}
    	}
    I can write to the text field with no problem's and if I set some text in the field before entering the IF statement, when the IF statement is entered it read's the text I have set with no problems.

    Any idea's?

    Cheers,

    DC%

  2. #2
    bubbless is offline Member
    Join Date
    Mar 2009
    Posts
    81
    Rep Power
    0

    Default

    Have you tried to output the textfield instead of using your own functions, so you are sure it reads it as blank/null?
    Maybe the problem lies in basicChat.

    Could you post more code?

  3. #3
    DC%
    DC% is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default

    I modified the code so that when the action was performed the value in the text field was printed:

    Java Code:
    System.out.println(screenname.getText());
    Which confirmed that is was always returning null unless a value was set before.

    I can post more code, anything particular you would like to see?

    DC%

  4. #4
    bubbless is offline Member
    Join Date
    Mar 2009
    Posts
    81
    Rep Power
    0

    Default

    Did it print nothing?
    Could you post the piece where the JTextField is made?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    My guess (and that's all I can do without more code) is that you have two separate and distinct instances of a jtextfield, perhaps by the same name, one displayed that you're not checking, and one that this method above is trying to check. If this doesn't help, you're going to have to post more code (though not too much!). Best of luck.

Similar Threads

  1. Replies: 1
    Last Post: 01-30-2009, 07:44 PM
  2. Got problem with JtextField
    By hungleon88 in forum AWT / Swing
    Replies: 4
    Last Post: 12-06-2008, 04:01 PM
  3. JtextField
    By kashifu in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2008, 05:25 PM
  4. Using Columns With JTextField
    By The Evil Genius in forum AWT / Swing
    Replies: 1
    Last Post: 03-17-2008, 02:01 AM
  5. help with JTextfield
    By gary in forum New To Java
    Replies: 4
    Last Post: 07-11-2007, 02:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •