Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

want to do some action when input is typed in Swing JPanel components  RSS feed

 
Nageswar Kakolla
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I want to do some action when user enters input in JPanel components such as JTextField, selection of JComboBox etc

and I tried KeyListener and KeyTyped

here is snippet of code which is invoked in constrctor of JPanel and ofcourse it is not working.

Ne help will be greatly appreciated

this.setFocusable(true);

KeyListener keyListener = new KeyListener(){

public void keyReleased(KeyEvent evt){
}
public void keyPressed(KeyEvent evt){

}
public void keyTyped(KeyEvent evt) {
String message = "Warning:Characters are Typed?";
m_dialog.invokeDialog(GUIConstants.QUESTION_DIALOG,message);

logger.debug("Key Typed"+evt.getKeyChar());
populateButtonPanel(m_previousButton,m_nextButton,m_cancelButton,m_saveButton);
}
};
this.addKeyListener(keyListener);
 
Anand Loni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am explaining this for JTextField. Add Document Lister to textfield
as
textField.getDocument().addDocumentListener(this);

for this listener you have to override three methods
insertUpdate();
removeUpdate();
changeUpdate();

Then u can do whatever u want in particular method.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!