JFormattedTextField, como selecionar o campo ?

29/09/2016

0

Boa tarde,

Sou iniciante no mundo java, gostaria de saber como selecionar o campo numero , para quando digitar o mesmo ele apagar os números, pois quando se iniciar o programa ele fica "0,00" eu queria que esse campo ficasse selecionado e apagasse quando digitasse , pois quando tento digitar no campo ele digita antes ou depois do zero.
obs: eu sei que tem como apagar manualmente, porem quero que o campo fique selecionado semelhante quando se aperta duas vezes no botão esquerdo do mouse
[code][private void edit_tipoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void edit_taxaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void edit_buttaoActionPerformed(java.awt.event.ActionEvent evt) {
CallculoJuros novo;
if(edit_tipo.getSelectedIndex() ==0){
novo = new CallculoJuros(TipoJuros.SIMPLES);
}else{
novo = new CallculoJuros(TipoJuros.COMPOSTO);
}

novo.setTaxa(novo.tratavirgula(edit_taxa.getText()));
novo.setValor(novo.tratavirgula(edit_taxa.getText()));
novo.setTempo(novo.tratavirgula(edit_tempo.getValue().toString()));

jTextField1.setText(String.format("%,2f",novo.getTotalJuros()));
jTextField2.setText(String.format("%,2f",novo.getValorJuros()));

// TODO add your handling code here:
}

private void edit_valorMouseClicked(java.awt.event.MouseEvent evt) {


}

private void edit_taxaMouseClicked(java.awt.event.MouseEvent evt) {

}

private void edit_valorFocusGained(java.awt.event.FocusEvent evt) {
edit_valor.selectAll();
}

private void edit_taxaFocusGained(java.awt.event.FocusEvent evt) {
edit_valor.selectAll();
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FormCalcular.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FormCalcular.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FormCalcular.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FormCalcular.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FormCalcular().setVisible(true);
}
});
}

// Variables declaration - do not modify
private java.awt.Button edit_buttao;
private javax.swing.JFormattedTextField edit_taxa;
private javax.swing.JSpinner edit_tempo;
private javax.swing.JComboBox<String> edit_tipo;
private javax.swing.JFormattedTextField edit_valor;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
]
Matheus Oliveira

Matheus Oliveira

Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar