नीचे दिया गया लिंक एक लेख है जो निर्धारित करता है कि कोई सेल दिखाई दे रहा है या नहीं। आप इसका उपयोग कर सकते हैं - यदि सेल दिखाई दे रहा है, तो पंक्ति दिखाई दे रही है। (लेकिन निश्चित रूप से, संभवतः पूरी पंक्ति नहीं, यदि क्षैतिज स्क्रॉलिंग भी मौजूद है।)
हालांकि, मुझे लगता है कि यह सेल विफल होने पर सेल विफल होने पर यह असफल हो जाएगा। इस मामले को संभालने के लिए, आप यह जांचने के लिए परीक्षण बदलते हैं कि सेल सीमा के ऊपर/नीचे व्यूपोर्ट की ऊर्ध्वाधर सीमा के भीतर है, लेकिन सेल के बाएं/दाएं हिस्से को अनदेखा करें। आयताकार की बाईं और चौड़ाई को 0 पर सेट करना सबसे आसान है। मैंने पंक्ति सूचकांक (कॉलम इंडेक्स की आवश्यकता नहीं) लेने के लिए विधि भी बदल दी है और यह तालिका true
लौटाती है यदि तालिका व्यूपोर्ट में नहीं है, जो लगता है अपने उपयोग-मामले के साथ बेहतर संरेखित करने के लिए।
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);
}
खैर, यह समाधान कम से कम मुझे सही सड़क पर डाल दिया गया है, यहाँ क्या मेरे लिए काम किया है: JViewport व्यूपोर्ट = scrollPane1.getViewport(); आयताकार rect = myTable.getCellRect (rowToSelect, 1, true); यदि (! Viewport.contains (rect.getLocation())) myTable.scrollRowToVisible (rowToSelect); । । । बहुत बहुत धन्यवाद – Brad