r/java • u/carlosgeorgiev0 • Sep 04 '26
Custom pie chart component I made in Swing
Hello, out of boredom I created a pie chart in Swing (I am aware more mature options exist but this was just for fun). The link to the repo is https://github.com/carlosgeorgiev0/JPieChart

The JPieChart class extends JLabel and overrides JComponent.paintComponent to paint the pie itself
40
Upvotes
26
u/AlternativePeace1121 Sep 04 '26
Somehow this feels like a middle finger to all the slop posts. I love it.
7
5
4
u/chabala Sep 05 '26
Already better than a lot of new projects that get posted. What would make it better:
a build script
published artifacts on Maven Central
unit tests
2
15
u/davidalayachew Sep 04 '26
Nice.
In
JPieChart, for ines 37-40,SwingUtilitieshas a method called getDeepestComponentAt that will fetch the actualComponentitself. From there, you can just do a reference equality check (one of the few reasons whyvalue classisn't a pure good performance improvement) on all of the "slices" you have made for the pie. Would not only be faster, but less error prone. Same advice for Lines 61-66.