• 1 reply
  • Latest Post - ‏2012-01-18T22:11:42Z by seohulu
1 Post

Pinned topic Problem to Populate value in TextField through Reflection

‏2011-11-11T04:34:32Z |
I have created a frame in swing.I put two text field and one apply button.
Now i put values over two text fields and click apply button.

Now i want to populate the text fields value through reflection in java what i have putted already .
try {
Class c = Class.forName("TestSwing.ReflectionOverJTextField");
Field f[] = c.getDeclaredFields();
for (int i = 0; i < f.length; i++)
Type ti = f[i].getGenericType();
JTextField b = new JTextField();// = new JTextField(x.toString());
String a =b.getText();//((f[i].getName())JTextField).getText().toString();
String fieldValue = (String) ReflectionOverJTextField.class.getDeclaredField(f[i].getName()).get((new JTextField()));
System.out.println("fieldValue = " + fieldValue);
} catch (Exception ex) {
Logger.getLogger(ReflectionOverJTextField.class.getName()).log(Level.SEVERE, null, ex);
This way i try. populate the values not for two text field. I want to populate values in generic way.
Updated on 2012-01-18T22:11:42Z at 2012-01-18T22:11:42Z by seohulu
  • seohulu
    8 Posts

    Re: Problem to Populate value in TextField through Reflection

    just a light,You can try to use BeanUtil to populate value from one instance to another instance, as long as the getter and setter of two instance matched.

    Acoolme is an Online Marketing Software Platform And Social Community