Koop
Koop

Reputation: 401

JLabel vs. drawString for efficiency

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.

Upvotes: 1

Views: 968

Answers (1)

camickr
camickr

Reputation: 324157

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.

Upvotes: 1

Related Questions