File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTextField : setText() is not working. getText() is working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField : setText() is not working. getText() is working" Watch "JTextField : setText() is not working. getText() is working" New topic

JTextField : setText() is not working. getText() is working

Arun Martin
Ranch Hand

Joined: Dec 01, 2000
Posts: 64
I have got a class AdminTabbedPane consisting of JTabbedPanes. I have added 2 JTabbedPanes
("Add New Mgmt Rep QC Rep","Modify Mgmt Rep QC Rep") to the main Class.
1. In the JTabbedPane "Add New Mgmt Rep QC Rep", I get values from the user and insert it into the database.
2. In the next JTabbedPane "Modify Mgmt Rep QC Rep", I retreive values from the database and setText the values in the
"Modify Mgmt Rep QC Rep" Pane. But then a funny thing happens. I am able to retreive values from the database and even print it on the screen and I am unable to setText the values. But when I use getText() after setText(), I am able to get the values. Strange indeed. When I declare a local String ie inside the "Modify Mgmt Rep QC Rep" Pane program,I am able to setText the local values.
What I suspect it's go to do something when the respective panes are clicked and loaded. I am using JDK1.3.
A Sample Outline of my code :

class AdminTabbedPane extends JFrame implements ChangeListener
Container container;
JTabbedPane tp;


tp = new JTabbedPane();
tp.addTab("Add New Mgmt Rep QC Rep",new
tp.addTab("Modify Mgmt Rep QC Rep",new
} // end of constructor AdminTabbedPane
public void stateChanged(ChangeEvent ce)
JTabbedPane tbpane;
tbpane = (JTabbedPane) ce.getSource();
int selectedIndex = tbpane.getSelectedIndex();
if (selectedIndex ==0)
new AddMgmtQC();
if (selectedIndex == 1)
System.out.println("just before the
modifymgmtqc pgm is called ");
new ModifyMgmtQC();
public static void main(String[] a)
// code
}// end of class AdminTabbedPane
class AddMgmtQC extends JPanel implements ActionListener
// declare all JTextFields and JLabels
public AddMgmtQC()
// code
public void actionPerformed(ActionEvent evt)
//get the values from the user and insert into the
class ModifyMgmtQC extends JPanel implements ActionListener
// code
declare a JTextField jtf
public ModifyMgmtQC()
// From the table I am retreiving the values.
// The values get displayed on the screen.
eg String dbvalue =res.getString(1); //
getting value from database
String InsertintotextField = dbvalue.trim()
// trimming spaces
System.out.println( InsertintotextField)
// gets displayed
// the text field is blank when displayed.
String getfromTextField = jtf.getText();
// gets displayed .
// nothing gets displayed

// if i declare String something="something"
// gets correctly displayed.
public void actionPerformed(ActionEvent evt)
// code

with warm regards,

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Maybe try repaint() your Panel after you setText().

GenRocket - Experts at Building Test Data
I agree. Here's the link:
subject: JTextField : setText() is not working. getText() is working
It's not a secret anymore!