JLabel setText not updating text

前端 未结 5 1787
日久生厌
日久生厌 2020-12-21 16:44

I am trying to update a JLabel by using the setText() method, but I can\'t redraw JLabel. Do I have to use the repaint() method to do that?

5条回答
  •  醉梦人生
    2020-12-21 17:11

    I'm a bit stumped on how the repainting of frames/component works in Java. You can Paint(Graphics g), update(Graphics g) which according to the javadoc just calls paint(g). Finally there's also repaint()...

    If none of those seem to work, wouldn't it just be easier to create the label only at the line where you are currently trying to set the text?

    Edit: there is also the option of using an ineditable textArea. Not only can it display the standard newline character, but you can put it in a jScrollPane, which is handy when you have lots of files in the log, and you don't need to repaint text components to display updated text. The bonus is magnificent imo...

提交回复
热议问题