这是我的应用程序的图像:
如您所见,其中有一个 JTable。我需要获取 JTable 的标头相对于它所在的 JFrame 的位置。
为什么我会这样做?我正在添加一个帮助功能来解释表中每一列的用途。它把焦点放在每一列上。它看起来像这样:
如您所见,聚光灯显示的位置已关闭。
要获取位置,我Rectangle
使用以下方法获取列标题:
getTable().getTableHeader().getHeaderRect(i);
要将其转换Rectangle
为 JFrame 中的正确位置,我使用:
Point point = SwingUtilities.convertPoint(
component, //the containing JPanel
rectangle.getLocation(), //the rectangle for the table column header
frame.getGlassPane()); //the containing JFrame
有人可以帮我获取列标题的正确位置吗?