我已經看到了一些這樣做的例子,但我仍然無法理解,無法實現它。如何做cellable上的JTable選擇所有文本
我想要做什麼是對細胞變化(焦點),下一個選擇的單元格將所有的文本選擇,隨時供用戶完全改變它..
關於如何做到這一點任何想法?
// //更新莫名其妙 我設法拿出下面的類,但
實現這個
tblLayers.setDefaultEditor(String.class,新Classes.CellEditor());
不會產生任何結果,「尚未支持」。不投擲..
我應該如何解決這個問題?
import java.awt.Component;
import java.util.EventObject;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.CellEditorListener;
import javax.swing.table.TableCellEditor;
public class CellEditor extends JTextField implements TableCellEditor {
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
// final JTextField ec = (JTextField) editorComponent;
//
// ec.setText((String) value);
//
// // selectAll, so that whatever the user types replaces what we just put there
// ec.selectAll();
//
// SwingUtilities.invokeLater(new Runnable() {
//
// public void run() {
// // make the component take the keyboard focus, so the backspace key works
// ec.requestFocus();
//
// SwingUtilities.invokeLater(new Runnable() {
//
// public void run() {
// // at this point the user has typed something into the cell and we
// // want the caret to be AFTER that character, so that the next one
// // comes in on the RHS
// ec.setCaretPosition(ec.getText().length());
// }
// });
// }
// });
// return editorComponent;
throw new UnsupportedOperationException("Not supported yet.");
}
public Object getCellEditorValue() {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean isCellEditable(EventObject anEvent) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean shouldSelectCell(EventObject anEvent) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean stopCellEditing() {
throw new UnsupportedOperationException("Not supported yet.");
}
public void cancelCellEditing() {
throw new UnsupportedOperationException("Not supported yet.");
}
public void addCellEditorListener(CellEditorListener l) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void removeCellEditorListener(CellEditorListener l) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
關於editorComponent,我在哪裏可以初始化這個變量? – Melvin