#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    JTextField dosn't refreshes when title changed


    hi, i got the following problem.

    i build a gui with a textfield. the displayed title is taken from an already existing object.
    Code:
    (label = new JLabel(object.getObjectName()); )
    putting this in position is also fine.
    i can see the text in the gui.

    the problem is, when i change the object via button(the name of it changes too) the label don't show the new name.

    i thought the gui refreshes itself all 5 millisec or is that something else?
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    when i change the object via button(the name of it changes too) the label don't show the new name
    To change the label after the object's contents changes, you need to call one of the label's methods with the new value.

    Is it like this:
    int x = 5;
    int y = x;
    x = 66; // would this change the value of y?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0
    of course not.
    i already tried to redraw/refresh it by using the same methods again in the actionPerformed of the button
    Code:
    public void actionPerformed(ActionEvent e){
    		if (e.getSource() == buttonID) {
    label = new JLabel(object.getObjectName());
    label.setBounds(1,2,3,4);
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Do you add the new JLabel to the container so it can be seen? What happens to the old JLabel that is currently being seen?

    Why don't you just change the text on the old JLabel that is being seen?

IMN logo majestic logo threadwatch logo seochat tools logo