Question

I have a hopefully simple question in regards to using JLabels vs. the paintComponents() .drawString() method. Is there any kind of benefit in using one over the other, assuming I never need to use any sort of .getText() or modifiers.

It seems messy to write a bunch of JLabels, and I dont particularly like the idea of a JTextAreas. However, I feel like using paintComponent for things other than shapes, colors, and pictures is maybe not the best idea.

Was it helpful?

Solution

It hard to answer your question since we don't know the exact requirement.

Don't worry about efficiency unless you've tested the application and you've identified a bottleneck and have isolated the problem.

In general, don't reinvent the wheel. There is no need to write custom code unless you are creating a custom component.

If you need to display text use a JLabel, JTextArea or whatever. Remember a JTextArea can be made to look like a JLabel by playing with the background and font etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top