JLabel 与drawString 的效率比较
我有一个关于使用 JLabels 与 PaintComponents() .drawString() 方法的简单问题。假设我永远不需要使用任何类型的 .getText() 或修饰符,使用其中一种比另一种有什么好处吗?
编写一堆 JLabels 看起来很混乱,而且我不太喜欢 JTextAreas 的想法。然而,我觉得将 PaintComponent 用于形状、颜色和图片以外的东西可能不是最好的主意。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很难回答你的问题,因为我们不知道确切的要求。
除非您已经测试了应用程序并且发现了瓶颈并隔离了问题,否则不必担心效率。
一般来说,不要重新发明轮子。除非您要创建自定义组件,否则无需编写自定义代码。
如果您需要显示文本,请使用 JLabel、JTextArea 或其他。请记住,通过调整背景和字体等,可以使 JTextArea 看起来像 JLabel。
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.