Thomas SMETS
Posts: 307
Nickname: tsmets
Registered: Apr, 2002
|
|
Re: creating own awt table
|
Posted: Apr 15, 2002 10:21 AM
|
|
Well if you use John ZUKOWSKI's book & unless you really heavy bitmaps, it should not be an issue.
I'll advise you to modify the code here under with you DataMode & keep the Runnable as it should be to also update you datas & you will see that unless you have thousands of records being diplayed, it should not be a issue !
Rgds,
Thomas,
p.s. : All my example need Log4J 1.2 Beta in the Classpath to run.
package test.gui;
import org.apache.log4j.Category;
import org.apache.log4j.BasicConfigurator;
import javax.swing.*;
import javax.swing.table.*;
public class ScrollTable
{
static public Category sLog = null;
public static void main(String[] args)
{
sLog = Category.getInstance (ScrollTable.class);
BasicConfigurator.configure ();
TableModel dataModel = new TableModel ();
JTable table = new JTable(dataModel);
JScrollPane scrollpane =
new JScrollPane(table);
scrollpane.setHorizontalScrollBarPolicy (
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
scrollpane.setVerticalScrollBarPolicy (
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JFrame frame = new JFrame();
frame.getContentPane ().add (scrollpane);
frame.setDefaultCloseOperation (frame.EXIT_ON_CLOSE);
frame.pack ();
frame.setSize( 300, 100);
frame.setVisible(true);
}
static class TableModel
extends AbstractTableModel
{
int offSet = 0;
TableModel()
{
Thread t = new Thread (
new Runnable ()
{
int i = getOffSet();
long startTime = System.currentTimeMillis ();
public static final long WAIT_TIME = 100;
public void run ()
{
long runTime;
do
{
runTime = System.currentTimeMillis () - startTime;
sLog.info (" i = " + i
+ " ( RunTime / ExpectedRunTime = " + runTime + " / " + (i*WAIT_TIME) + " )");
try
{
Thread.sleep (WAIT_TIME);
} catch (Exception ex)
{
}
setOffSet(i++);
} while (true);
}
}
);
t.start();
}
public int getColumnCount()
{
return 10000;
}
public int getRowCount()
{
return 1000;
}
public Object getValueAt(int row, int col)
{
sLog.info ("getValueAt (row " + row + ", col "+ col + ") ");
return new Integer(row*col+offSet);
}
public int setOffSet(int newOffSet)
{
offSet = newOffSet;
fireTableDataChanged ();
return offSet;
}
public int getOffSet()
{ return offSet; }
} // End of inner class
}
|
|