This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes fieldName.setText is not setting text. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "fieldName.setText is not setting text." Watch "fieldName.setText is not setting text." New topic

fieldName.setText is not setting text.

Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31

Background of problem : I have created a Form that has several Text field, trying to link to the backend DB to display data on the from.

Problem : I have used the fieldName.setText property to set the value that I am getting from the Query, for some reason it is not setting the value..

As you can see, the System.out.print does print the values right.. But I cannot see it on my Form view.. Why would that be?

Does it make a difference if they are on different panels? I have one jFrame and three jPanels.. All the text fields are scattered among these panels like Title maybe in Panel1 and F_Name in Panel2 etc....
Ranganathan Kaliyur Mannar

Joined: Oct 16, 2003
Posts: 1076

You mention that you added the field to 'Form'. What is Form? is it your own class? does it extend JPanel?

First of all, does your screen display properly i.e is the text field visible? I would suggest you to write a small program without the DB part and try the call to setText directly.

Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
Form is just the way I call it.. It is just a Panel with all the TextFields on it..

The text fields are all visible.. However I tried adding something like

Even which did not seem to appear..
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Well, clearly you've done something wrong then. But from the code you've posted, it's impossible to tell what that is. In fact we can't even tell what kind of component txt_TITLE is.

So you're going to have to post your code. But we don't want to see 900 lines of code, if that's what you have. What we need to see is a small example which demonstrates the problem. Read the page here: SSCCE which explains that in more detail.
Andrew Geroge Alexander
Ranch Hand

Joined: Feb 14, 2012
Posts: 31
Hello.. Sorry it was something I did.. I called a non static function by creating an object, before the default constructor was called.. thus making the previous object void/overridden by the normal constructor.. So i deleted the default coding and it works..
It is sorta covered in the JavaRanch Style Guide.
subject: fieldName.setText is not setting text.
Similar Threads
Session variable returns null value
retreiving all rows from a mysql table to a jsp page
problem in extracting values from ResultSet
servlet is not working properly
error showing while retrieving the data from drop down list