EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----

-

Make a cell/row visible


Author: Zafir Anjum

Make a cell or row visible programmatically.


	static void setCellVisible( JTable table, int row, int col )
	{
		Container p = table.getParent();
		if (p instanceof JViewport) {
			Container gp = p.getParent();
			if (gp instanceof JScrollPane) {
				JScrollPane scrollPane = (JScrollPane)gp;
				// Make sure the table is the main viewport
				JViewport viewport = scrollPane.getViewport();
				if (viewport == null || viewport.getView() != table) {
					return;
				}
				
				Rectangle cellrect = table.getCellRect( row, col, true );
				Rectangle viewrect = viewport.getViewRect();
				if( viewrect.contains( cellrect ) )
					return;
				Rectangle union = viewrect.union( cellrect );
				int x = (int)(union.getX() + union.getWidth() - viewrect.getWidth());
				int y = (int)(union.getY() + union.getHeight() - viewrect.getHeight());
				viewport.setViewPosition( new Point( x, y ) );
			}
		}
		
	}

Posted On: 7-Jan-1999

internet.commerce