重叠AWT线和Swing的JLabel [英] Overlapping AWT lines and Swing JLabels

查看:208
本文介绍了重叠AWT线和Swing的JLabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用我行原语和 JLables 在我的应用程序有问题。我试图解释它:

I have a problem in my application using line primitives and JLables. I try to explain it:


  • 我在使用线重新present道路和的JLabel 重新present城市绘制车辆路线。我需要使用的JLabel 的,因为每个JLabel的有一个监听器,显示与有关城市的信息的对话框。

  • 我重新定义的paint()我的主要方法的JP​​anel 。在该方法中我第一次调用 super.paint(),然后我绘制线条,最后我的标签添加到的JP​​anel

  • I have to draw a vehicle route using lines to represent roads and JLabels to represent cities. I need the use of JLabels because each JLabel has a Listener that shows a dialog with information about the city.
  • I redefine paint() method of my main JPanel. In that method I first in invoke the super.paint(), then I draw the lines and finally I add the Labels to the JPanel.

的问题是,该线重叠的标签不管无关紧要画它们的顺序。请问有什么建议吗?

The problem is that the lines overlap the labels regardless the matter the order of painting them. Is there any suggestion?

推荐答案

您还可以覆盖的paintComponent() paintChildren()的JP​​anel 方法。
paintChildren()打电话给你的线条绘制,然后超级绘制的JLabel

You can also override paintComponent() or paintChildren() methods of the JPanel. In the paintChildren() call your lines drawing and then super to draw JLabels.

这篇关于重叠AWT线和Swing的JLabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆