aspose file tools*
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
Author

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

Arun Martin
Ranch Hand

Joined: Dec 01, 2000
Posts: 64
Hi,
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.
Problem:
--------
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;

AdminTabbedPane()
{
container=this.getContentPane();

tp = new JTabbedPane();
tp.addChangeListener(this);
tp.addTab("Add New Mgmt Rep QC Rep",new
AddMgmtQC());
tp.setBackgroundAt(0,Color.white);
tp.addTab("Modify Mgmt Rep QC Rep",new
ModifyMgmtQC());
tp.setBackgroundAt(1,Color.white);
} // 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
database
}
}
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
jtf.setText(InsertintotextField);
// the text field is blank when displayed.
String getfromTextField = jtf.getText();
System.out.println(getfromTextField);
// gets displayed .
jtf.setText(getfromTextField)
// nothing gets displayed


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


with warm regards,
Arun.








Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextField : setText() is not working. getText() is working