1795 */ 1796 public void paint(Graphics g, JComponent c) { 1797 Rectangle clip = g.getClipBounds(); 1798 1799 Rectangle bounds = table.getBounds(); 1800 // account for the fact that the graphics has already been translated 1801 // into the table's bounds 1802 bounds.x = bounds.y = 0; 1803 1804 if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 || 1805 // this check prevents us from painting the entire table 1806 // when the clip doesn't intersect our bounds at all 1807 !bounds.intersects(clip)) { 1808 1809 paintDropLines(g); 1810 return; 1811 } 1812 1813 boolean ltr = table.getComponentOrientation().isLeftToRight(); 1814 1815 Point upperLeft = clip.getLocation(); 1816 Point lowerRight = new Point(clip.x + clip.width - 1, 1817 clip.y + clip.height - 1); 1818 1819 int rMin = table.rowAtPoint(upperLeft); 1820 int rMax = table.rowAtPoint(lowerRight); 1821 // This should never happen (as long as our bounds intersect the clip, 1822 // which is why we bail above if that is the case). 1823 if (rMin == -1) { 1824 rMin = 0; 1825 } 1826 // If the table does not have enough rows to fill the view we'll get -1. 1827 // (We could also get -1 if our bounds don't intersect the clip, 1828 // which is why we bail above if that is the case). 1829 // Replace this with the index of the last row. 1830 if (rMax == -1) { 1831 rMax = table.getRowCount()-1; 1832 } 1833 1834 int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight); 1835 int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft); 1836 // This should never happen. 1837 if (cMin == -1) { 1838 cMin = 0; 1839 } 1840 // If the table does not have enough columns to fill the view we'll get -1. 1841 // Replace this with the index of the last column. 1842 if (cMax == -1) { 1843 cMax = table.getColumnCount()-1; 1844 } 1845 1846 // Paint the grid. 1847 paintGrid(g, rMin, rMax, cMin, cMax); 1848 1849 // Paint the cells. 1850 paintCells(g, rMin, rMax, cMin, cMax); 1851 1852 paintDropLines(g); 1853 } 1854 1855 private void paintDropLines(Graphics g) { 1856 JTable.DropLocation loc = table.getDropLocation(); 1857 if (loc == null) { 1858 return; 1859 } 1860 1861 Color color = UIManager.getColor("Table.dropLineColor"); 1862 Color shortColor = UIManager.getColor("Table.dropLineShortColor"); 1863 if (color == null && shortColor == null) { | 1795 */ 1796 public void paint(Graphics g, JComponent c) { 1797 Rectangle clip = g.getClipBounds(); 1798 1799 Rectangle bounds = table.getBounds(); 1800 // account for the fact that the graphics has already been translated 1801 // into the table's bounds 1802 bounds.x = bounds.y = 0; 1803 1804 if (table.getRowCount() <= 0 || table.getColumnCount() <= 0 || 1805 // this check prevents us from painting the entire table 1806 // when the clip doesn't intersect our bounds at all 1807 !bounds.intersects(clip)) { 1808 1809 paintDropLines(g); 1810 return; 1811 } 1812 1813 boolean ltr = table.getComponentOrientation().isLeftToRight(); 1814 1815 // compute the visible part of table which needs to be painted 1816 Rectangle visibleBounds = clip.intersection(bounds); 1817 Point upperLeft = visibleBounds.getLocation(); 1818 Point lowerRight = new Point(visibleBounds.x + visibleBounds.width - 1, 1819 visibleBounds.y + visibleBounds.height - 1); 1820 1821 int rMin = table.rowAtPoint(upperLeft); 1822 int rMax = table.rowAtPoint(lowerRight); 1823 // This should never happen (as long as our bounds intersect the clip, 1824 // which is why we bail above if that is the case). 1825 if (rMin == -1) { 1826 rMin = 0; 1827 } 1828 // If the table does not have enough rows to fill the view we'll get -1. 1829 // (We could also get -1 if our bounds don't intersect the clip, 1830 // which is why we bail above if that is the case). 1831 // Replace this with the index of the last row. 1832 if (rMax == -1) { 1833 rMax = table.getRowCount()-1; 1834 } 1835 1836 int cMin = table.columnAtPoint(ltr ? upperLeft : lowerRight); 1837 int cMax = table.columnAtPoint(ltr ? lowerRight : upperLeft); 1838 // This should never happen. 1839 if (cMin == -1) { 1840 cMin = 0; 1841 } 1842 // If the table does not have enough columns to fill the view we'll get -1. 1843 // Replace this with the index of the last column. 1844 if (cMax == -1) { 1845 cMax = table.getColumnCount()-1; 1846 } 1847 1848 Container comp = SwingUtilities.getUnwrappedParent(table); 1849 if (comp != null) { 1850 comp = comp.getParent(); 1851 } 1852 1853 if (comp != null && !(comp instanceof JViewport) && !(comp instanceof JScrollPane)) { 1854 // We did rMax-1 to paint the same number of rows that are drawn on console 1855 // otherwise 1 extra row is printed per page than that are displayed 1856 // when there is no scrollPane and we do printing of table 1857 // but not when rmax is already pointing to index of last row 1858 if (rMax != (table.getRowCount() - 1)) { 1859 rMax = rMax - 1; 1860 } 1861 } 1862 1863 // Paint the grid. 1864 paintGrid(g, rMin, rMax, cMin, cMax); 1865 1866 // Paint the cells. 1867 paintCells(g, rMin, rMax, cMin, cMax); 1868 1869 paintDropLines(g); 1870 } 1871 1872 private void paintDropLines(Graphics g) { 1873 JTable.DropLocation loc = table.getDropLocation(); 1874 if (loc == null) { 1875 return; 1876 } 1877 1878 Color color = UIManager.getColor("Table.dropLineColor"); 1879 Color shortColor = UIManager.getColor("Table.dropLineShortColor"); 1880 if (color == null && shortColor == null) { |