2

I am new to Java but needs to know that if it is possible for a developer so that he/she can change the shape of the JProgressBar. I mean suppose in my case I want to change the shape so that it looks like a circle or something else?

Though I just want it to be changed from a bar shape to an arc shape or you can say i want to change the bar shape into any other shape. My progress bar may look like a curve other than a bar shape. I want to add a curve in it.

Tech Nerd
  • 822
  • 1
  • 13
  • 39

1 Answers1

7

The appearance of a JProgressBar is controlled by the component's UI delegate, typically derived from BasicProgressBarUI. You can supply your own delegate, as shown here, and override the desired paint method.

Addendum: For a semi-circular display, you may be able to leverage DialPlot from the JFreeChart library. A complete example is discussed here. You can use it directly or render the chart in your UI delegate.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I want to change the shape not the colors thanks for your help over and out @trash – Tech Nerd Apr 24 '13 at 03:33
  • You can use whatever color(s) you want; it won't automatically match the platform default, but you can use the UI [defaults](http://stackoverflow.com/a/11148842/230513) as a start. – trashgod Apr 24 '13 at 03:45
  • You can also change the shape in the UI delegate, but then you can reuse less code from BasicProgressBarUI. Not an easy task. Check out http://javagraphics.blogspot.co.at/2008/05/angles-need-gui-widget-for-angles.html - here an "angle UI" is given to a JSlider. – lbalazscs Apr 24 '13 at 12:28
  • @lbalazscs the link you mentioned has no such information sorry for asking from you – Tech Nerd Apr 24 '13 at 17:25
  • That link is just an example, it shows how one can use a completely different-looking UI delegate for a Swing component. It does not solve your problem directly. – lbalazscs Apr 25 '13 at 10:03
  • See also this [approach](http://stackoverflow.com/a/16333445/230513). – trashgod May 02 '13 at 13:08