所以你可能知道,如果你有一个文本字段,并添加一个ActionListener,它只会听按键的按钮.但是,我想让我的ActionListener听取文本中的更改.所以基本上我有这个:
- public static JPanel mainPanel() {
- JPanel mainp = new JPanel();
- JTextArea areap = new JTextArea("Some text in the textarea");
- JTextField fieldp = new JTextField("Edit this");
- areap.setEditable(false);
- fieldp.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- if(//change in textfield,for instance a letterpress or space bar)
- {
- //Do this
- }
- }
- });
- mainp.add(areap);
- mainp.add(fieldp);
- return mainp;
- }
任何方式我都可以听取文本中的更改(如actionPerformed事件中记录的)?