JProgressBar setValue is not working, tried with SwingUtilities as well

前端 未结 3 826
不思量自难忘°
不思量自难忘° 2020-12-19 23:10

I have implemented a JProgressBar in a JTable. I used renderer for the ProgressBar NOT EDITOR.

Now I tried to implement a ProgressBar set value but

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-19 23:38

    Take a look at the Swing table tutorial: renderers and editors. The renderer uses the component to make a sort of 'stamp'. Changing the component afterwards has no effect since the component is not actually contained in your UI. That is one of the reasons you can return the same component over and over again, which would not be possible if the component was actually contained in the table. This is all explained in the linked tutorial.

    To solve your problem, just remove the SwingUtilities.invokeLater method call, and return a JProgressBar where the correct progress is set.

    And if I see this correctly, you have a TableModel containing a JProgressBar. I hope there is a good reason for this, since this is a UI component which should normally not be included on the model side. This is based on your

    final JProgressBar bar = (JProgressBar) value;
    

    call in the renderer. I would strongly suggest to take a look at your TableModel to see whether this can be avoided

提交回复
热议问题