When creating a GUI in Java with Swing, how should more advanced "elements" be created? As an example, consider:

This could be done using ~10 images depending on the current page or status. I'm also sure that it'd be possible to do this programmatically, however, considering my past experiences with Swing, I'm also sure it'd be a lot of code for something relatively simple. Especially considering this could be done in CSS with max ~40 lines of code.
In a situation like this, is there any alternative approach to create this "element"? If not; what's preferred: images or Swing?
You can use a suitable Unicode glyph, e.g. ✓—CHECK MARK or any digit,
as a label's text, shown here.
as a GlyphVector, mentioned here.
as a rendered image, illustrated here.
You can get a tinted, anti-aliased circle by implementing the Icon interface; ColorIcon is an example.
You can get a variety of solid and dashed lines using BasciStroke, seen here.
Among the stock layout managers, FlowLayout may be adequate.
This will come down to the requirements.
If you want it to be scalable, then Swing graphics is your best choice. If not, images should be fine. If you want it to be reusable (for n possible connections) then Swing graphics is a better choice. If you have a limited number of connections that will never change, the images will be fine.
You also need to consider how easy it would be to change the look and feel. Images will take time to create, but renderers provide more flexibility.
For me, I'd generally use a combination of the two. Rendering text is relatively simple, but things like the check mark would take more time to create.
You've also got to take into consider if you want to produce a single image and render it, it use separate components for each part.
I'd also consider things like navigation. Do you need it, if so, is it easier to use components with MouseListeners or convert the view to the model to determine what's going.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With