I'm building a database table editor using JDBC 2 and a JTable. The editor
works great, but i'd like to be able to add functionality to it such that a
user can select a row, cut/copy it into his/her (windows) clipboard and then
paste it into a new row. My questions are a) is this possible with jdk1.2.2
b) has anyone done it before and c) would you have any sample code and/or
suggestions on how to get started with this. Thanks for your time.
-Frank
--
"If debugging is the process of removing bugs, then programming must be the
process of putting them in." -- Dijkstra
The only object I succeed to put in the system clipboard is a String so I
took my data and tranformed it as a String before the cut/copy and I rebuild
the data with the String at the paste.
The nice thing to this is that you can import/export from/to a text editor,
Excel, Quattro Pro.
The cut function is a copy + a delete.
shSelected is a object of class Category that implement TableModel and that
contain LearnElement (1 row = 1 LearnElement and 1 LearnElement contains
several Strings (the columns))
Here is the code for the copy :
for (int i=0;i<rows.length;i++) {
for (int j=0;j<shSelected.getColumnCount();j++) {
data += shSelected.getValueAt(rows[i],j)+"\t";
}
data = data.substring(0,data.length()-1);
data += "\n";
}
StringSelection stSelection = new StringSelection(data);
Clipboard clipBrd = Toolkit.getDefaultToolkit().getSystemClipboard();
clipBrd.setContents(stSelection,stSelection);
Here is the code for the paste:
Clipboard clipBrd = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable content = clipBrd.getContents(this);
if (content.isDataFlavorSupported(DataFlavor.plainTextFlavor)) {
try {
String data =
(String)content.getTransferData(DataFlavor.stringFlavor);
System.out.println(data);
Category shSelected = getLastSelectedSheet();
StreamTokenizer stData = new StreamTokenizer(new
StringReader(data));
stData.eolIsSignificant(true);
stData.wordChars((int)' ',(int)' ');
stData.whitespaceChars((int)'\t',(int)'\t');
LearnElement wdData = new LearnElement();
int cmpt = 0;
while (stData.nextToken()!=stData.TT_EOF) {
if (stData.ttype==stData.TT_EOL) {
shSelected.addLearnElement(wdData);
wdData = new LearnElement();
cmpt = 0;
} else {
String token = stData.sval;
wdData.setWordIn(token,cmpt);
cmpt++;
}
}
Bonne Chance! (Good luck!)
Anthony
Frank Corrao wrote in message <7ph62r$qh2$1...@newsfeeds.rpi.edu>...