Finding a way to be notified when ENTER is pressed in a JTextPane

I want to be able to do some processing when the ENTER key is pressed in JTextPane. However I also want the key to do what it is supposed to do - begin a new line. I can map the ENTER key to do processing, and I can map it to insert a newline. But I can't seem to do both. There has to be a way to be notified when the ENTER key is pressed so that I can use the notification to initiate other processing.

This could involve being able to read each character as it is input to the JTextPane and when the ENTER key is pressed or newline is entered, an if statement could be used.But I'm at a lost as to how to get the script to read each character.

Any help would be greatly appreciated.

Thanks

[719 byte] By [chanteura] at [2007-10-2 19:14:53]
# 1
why don't you try keystrokes and action map.
skdagaa at 2007-7-13 20:56:26 > top of Java-index,Security,Event Handling...
# 2

JFrame frame = new JFrame();

JTextPane pane = new JTextPane();

frame.getContentPane().add(pane);

KeyStroke enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,true);

ActionListener tempActionListener = new ActionListener() {

public void actionPerformed(ActionEvent ae) {

System.out.println("Enter Pressed");

}

};

pane.registerKeyboardAction(tempActionListener,enterKeyStroke,JComponent.WHEN_FOCUSED);

frame.pack();

frame.setVisible(true);

skdagaa at 2007-7-13 20:56:26 > top of Java-index,Security,Event Handling...
# 3
Thanks very much.
chanteura at 2007-7-13 20:56:26 > top of Java-index,Security,Event Handling...