Java JTable mastering
April 28th, 2009
No comments
JAVA:
-
//My custom cell editor
-
import java.awt.Color;
-
import java.awt.Component;
-
-
import javax.swing.BorderFactory;
-
import javax.swing.DefaultCellEditor;
-
import javax.swing.JComboBox;
-
import javax.swing.JTable;
-
import javax.swing.JTextField;
-
-
private static final long serialVersionUID = 1L;
-
-
JTextField jtf;
-
-
public MyCellEditor() {
-
}
-
-
boolean isSelected, int row, int column){
-
-
-
jtf.selectAll();
-
}
-
-
return c;
-
}
-
}
JAVA:
-
/*
-
* TableTest.java
-
*
-
* Created on 08 July 2004, 11:07
-
*/
-
-
/**
-
*
-
* @author admin
-
*/
-
import javax.swing.JTable;
-
-
-
javax.swing.JTextField jtf;
-
-
public MyEditor(){
-
-
}
-
-
jtf.selectAll();
-
//jtf.setText("");
-
//jtf.setCaretPosition(0);
-
}
-
-
return c;
-
}
-
-
}
-
-
/** Creates new form TableTest */
-
public TableTest() {
-
initComponents();
-
((javax.swing.DefaultCellEditor)jTable1.getDefaultEditor(new Object().getClass())).setClickCountToStart(1);
-
-
//jTable1.setDefaultEditor(new Object().getClass(), new MyEditor());
-
-
}
-
-
/** This method is called from within the constructor to
-
* initialize the form.
-
* WARNING: Do NOT modify this code. The content of this method is
-
* always regenerated by the Form Editor.
-
*/
-
private void initComponents() {
-
-
exitForm(evt);
-
}
-
});
-
-
{"jtable1", "jtable1", "jtable1", "jtable1"},
-
{"jtable1", "jtable1", "jtable1", "jtable1"},
-
{"jtable1", "jtable1", "jtable1", "jtable1"},
-
{"jtable1", "jtable1", "jtable1", "jtable1"}
-
},
-
"Title 1", "Title 2", "Title 3", "Title 4"
-
}
-
));
-
-
{"jtable2", "jtable2", "jtable2", "jtable2"},
-
{"jtable2", "jtable2", "jtable2", "jtable2"},
-
{"jtable2", "jtable2", "jtable2", "jtable2"},
-
{"jtable2", "jtable2", "jtable2", "jtable2"}
-
},
-
"Title 1", "Title 2", "Title 3", "Title 4"
-
}
-
));
-
-
jLabel1.setText("JTable clear selection on focus loss example by cjard@hotmail.com");
-
-
pack();
-
}
-
-
/** Exit the Application */
-
}
-
-
/**
-
* @param args the command line arguments
-
*/
-
new TableTest().show();
-
}
-
-
// Variables declaration - do not modify
-
// End of variables declaration
-
-
}