[英]how to get current position of selected cell (JComboBox )in JTable
[英]Get Position of a selected JTable cell?
我有一個帶有幾個JTable的JFrame。 在一個特定的JTable上,我需要在選擇的JFrame中選擇單元格的位置(通過代碼完成選擇)。 我想在Glass Pane上畫一些東西。 我怎么能做到這一點?
Point p = gui.rerouteTable.getLocation();
SwingUtilities.convertPointToScreen(p,gui.rerouteTable);
我以為這可以讓我在桌子的左上角。 通過Cell Height和SelectionListener,我可以克服我需要的位置。 但我甚至得不到桌子的左手角落。 為什么不? gui.rerouteTable.getLocation()返回(0,0)所以很明顯convertPointToScreen無法正常工作。
使用JTable的方法
public Rectangle getCellRect(int row, int column, boolean includeSpacing)
如果由於其他原因不需要玻璃窗格,還可以考慮使用isSelected
值來調整渲染器外觀的自定義單元格渲染器。
附錄:每次為特定單元TableCellRenderer
用TableCellRenderer
,名為value
的參數是對從該單元格的模型獲取的Object
的引用。
使用此代碼,您可以獲取表格中單元格的x和y坐標:
private void jtTableMouseClicked(java.awt.event.MouseEvent evt) {
int x = jtTable.getSelectedRow();
int y = jtTable.getSelectedColumn();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.