Edition JTextField dans ma JTable
Bonjour,
Je suis actuellement en stage et je dois créer une interface graphique pour les personnes devant aller sur le terrain saisir des données.
Un de mes écrans est sous forme de table dans laquelle se trouve 3 JComboBox et 1 JTextField.
Lors de l'ajout tout se passe bien, j'ai mes Combo qui s'affiche ainsi que mon champ de texte.
Seulement lorsque je veux écrire qqch à l'intérieur de mon JTextField, impossible de voir le curseur clignoter...
Lorsque je tape une lettre ou autres choses dans mon JTextField, celle-ci s'affiche mais il y a déjà une longue phrase écrite à l'intérieur qui s'affiche en même temps ...
Je ne comprend pas pourquoi et je n'arrive pas à faire en sorte qu'elle ne s'affiche pas.
Je vous joint quelques bout de mon code.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
public class TableComponent extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
if (value instanceof JTextField){
((JTextField) value).setText(" ");
return (JTextField) value;
}
else if(value instanceof JComboBox){
return (JComboBox) value;
}
else
return this;
} |
Voici ma class d'affichage :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
//Déclaration des champs du panel éspèce
JComboBox espece_nom_latin = new JComboBox(Constantes.CONST_NOM_LATIN_ESPECE);
JComboBox espece_strates = new JComboBox(Constantes.CONST_STRATES);
JComboBox espece_coef_abondance = new JComboBox(Constantes.CONST_COEFFICIENT_ABONDANCE);
JTextField espece_nom_saisie = new JTextField();
//Déclaration du tableau d'objet pour remplir la table
private Object [][] espece_tab;
public FloreEspece(){
//Création du tableau d'objet
this.espece_tab = new Object[][]{{this.espece_nom_latin,this.espece_nom_saisie,this.espece_strates,this.espece_coef_abondance,}};
//Création du panel espece
this.setPreferredSize(new Dimension (1150,590));
//Création de la table
this.table = new JTable();
this.table.setGridColor(Color.BLACK);
this.table.setPreferredScrollableViewportSize(this.getPreferredSize());
this.table.setModel(new TableModele (this.espece_tab,Constantes.CONST_TABLE_MODELE));
this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.table.setRowHeight(22);
this.table.setDefaultRenderer(JComponent.class, new TableComponent());
this.table.getColumn("Choix").setCellEditor(new DefaultCellEditor(this.espece_nom_latin));
this.table.getColumn("Nom de l'éspèce").setCellEditor(new DefaultCellEditor(this.espece_nom_saisie));
this.table.getColumn("Strate").setCellEditor(new DefaultCellEditor(this.espece_strates));
this.table.getColumn("Abondance/Dominance").setCellEditor(new DefaultCellEditor(this.espece_coef_abondance));
this.scrollpane = new JScrollPane(table);
//Ajout du scrollpane(la table) au panel espece
this.add(this.scrollpane);
}
public Class getColumnClass(int col){
return this.espece_tab[0][col].getClass();
}
} |
Merci