0

I created a class test with many data members of which one is a JTextField called myField. During the construction, I create a blank text field.

My problem is that, the contents of the text field never changes after construction if I use setText method.

class test extends JPanel
{
    private JTextField myField;
    public test()
    {
        //constructer
    }
    private void setTheLayout()
    {
        // did layout positioning for myField
        add(myField);
    }
    private void setAValue() //called on a button click
    {
        myField.setText("Hello world");
    }
}

How to solve this?

4

1 回答 1

0

更改: private JTextField myField;至:private JTextField myField = new JTextField("");

我认为这就是你所需要的。

于 2013-08-22T15:56:17.783 回答