2010-05-01 19 views

cevap

1

Aşağıdaki bağlantı, bir hücrenin görünüp görünmeyeceğini belirleyen bir makaleye yöneliktir. Bunu kullanabilirsiniz - hücre görünürse, satır görünür. (Ancak, yatay kaydırma da mevcutsa, muhtemelen tüm satır değil.)

Ancak, bu, hücre görünümden daha geniş olduğunda başarısız olacağını düşünüyorum. Bu durumu ele almak için, sınamanın üst/altının görünümün dikey kapsamı içinde olup olmadığını kontrol etmek için testi değiştirirsiniz, ancak hücrenin sol/sağ bölümünü göz ardı edin. Dikdörtgenin sol ve genişliğini 0'a ayarlamak en basit olanıdır. Ayrıca, yalnızca satır dizinini (sütun dizinine gerek yoktur) almak için yöntemi değiştirdim ve tablo bir görünümdeyken true döndürür kullanım durumunuzla daha iyi hizalamak için.

public boolean isRowVisible(JTable table, int rowIndex) 
{ 
    if (!(table.getParent() instanceof JViewport)) { 
     return true; 
    } 

    JViewport viewport = (JViewport)table.getParent(); 
    // This rectangle is relative to the table where the 
    // northwest corner of cell (0,0) is always (0,0) 

    Rectangle rect = table.getCellRect(rowIndex, 1, true); 

    // The location of the viewport relative to the table  
    Point pt = viewport.getViewPosition(); 
    // Translate the cell location so that it is relative 
    // to the view, assuming the northwest corner of the 
    // view is (0,0) 
    rect.setLocation(rect.x-pt.x, rect.y-pt.y); 
    rect.setLeft(0); 
    rect.setWidth(1); 
    // Check if view completely contains the row 
    return new Rectangle(viewport.getExtentSize()).contains(rect); 
} 
+0

Eh, bu çözüm en azından doğru yolda beni koydu, burada benim için çalıştı budur: JViewport viewport = scrollPane1.getViewport(); Dikdörtgen rect = myTable.getCellRect (rowToSelect, 1, doğru); if (! Viewport.contains (rect.getLocation())) myTable.scrollRowToVisible (rowToSelect); . . . Çok teşekkürler – Brad

İlgili konular