Posted Tuesday, November 1, 2005 @ 23:29:41
I'm trying to bypass invisible and readonly columns with the TAB key.
In using the MyDBTableEventListerner.afterColumnSelectionChange,
I try to figure out that if is not a "non-TABable" field, I move to the next.
The problem is when I try to change rows. It just would not work, it keeps returning to the old row.
The below is a progra you can try. Try to TAB through - it drives me nuts.
It seems quicktable is calling:
setValueAt() didn't update the data R1C1 at row=1 col=2 because new value same as old value
and resetting the selected row.
import java.awt.BorderLayout;
import java.io.*;
import java.util.Properties;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import quick.dbtable.*;
/*
* dBTableTest.java
*
* Created on August 21, 2005, 3:43 AM
*/
public class dBTableTest1 extends JFrame {
DBTable dBTable1;
/** Creates a new instance of dBTableTest */
public dBTableTest1(PipedOutputStream pOut) {
Properties prop = new Properties();
prop.put("delimiter","\t");
prop.put("firstRowHasColumnNames","true");
setSize(500,200);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
// InputStream in = new InputStream();
dBTable1 = new DBTable();
try {
PipedInputStream pIn = new PipedInputStream(pOut);
getContentPane().add(dBTable1, BorderLayout.CENTER);
dBTable1.refresh(pIn,prop);
dBTable1.addDBTableEventListener(new MyDBTableEventListerner());
Column col = dBTable1.getColumn(0);
col.setVisible(false);
col = dBTable1.getColumn(4);
col.setVisible(false);
col = dBTable1.getColumn(3);
// col.setReadOnly(true);
dBTable1.editCellAt(0,1);
} catch (Exception e) {
e.printStackTrace();
}
}
class MyDBTableEventListerner extends quick.dbtable.DBTableEventListener {
public void afterRowSelectionChange(int fromRow, int toRow) {
// this is done before ColumnChange
int col = dBTable1.getSelectedColumn();
System.out.println("After changing Row from " + fromRow + " to " + toRow + " col " + col);
}
public void afterColumnSelectionChange(int fromColumn, int toColumn) {
int nowRow = dBTable1.getSelectedRow();
if (toColumn == 0 && fromColumn == dBTable1.getColumnCount() -1) {
nowRow++;
}
System.out.println("After changing Col from " + fromColumn + " to " + toColumn + " row " + nowRow);
Column column = dBTable1.getColumn(toColumn);
int c = toColumn;
System.out.print("Moving from " + nowRow +"," + c);
while ((! column.isVisible() || column.getReadOnly() == true ) && c < dBTable1.getColumnCount() ) {
c++;
if (c == dBTable1.getColumnCount()) {
c = 0;
nowRow++;
if (nowRow == dBTable1.getRowCount()) {
// possibly insertRow
nowRow = 0;
}
}
System.out.print(">" + c);
column = dBTable1.getColumn(c);
}
System.out.println(" to " + nowRow + "," +c);
if (c != toColumn) {
dBTable1.debug = true;
dBTable1.selectCell(nowRow,c);
dBTable1.getTable().changeSelection(nowRow,c, false, false);
}
}
// not called !!!!!
public boolean beforeColumnSelectionChange(int fromColumn,
int toColumn,
int fromRow,
int toRow) {
System.out.println("Before changing from " + fromRow + "," + fromColumn + " to " + toRow + "," + toRow);
return true;
}
}
public static void writer(PipedOutputStream pOut) {
StringBuffer buf = new StringBuffer();
buf.append("Column0\tColumn 1\tColumn 2\tColumn 3\tColumn 4\n");
buf.append("R0C0\tR0C1\tR0C2\tROC3\tROC4\n");
buf.append("R1C0\tR1C1\tR1C2\tR1C3\tR1C4\n");
buf.append("R2C0\tR2C1\tR2C2\tR1C3\tR2C4\n");
String s = new String(buf);
byte[] byteArray = s.getBytes();
try {
pOut.write(byteArray);
pOut.flush();
pOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
final PipedOutputStream pOut = new PipedOutputStream();
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
dBTableTest1 comp = new dBTableTest1(pOut);
comp.setVisible(true);
comp.toFront();
}
});
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
writer(pOut);
}
});
}
}