How to set the caret to the next new line/and how to clean a Image Icon frm da memory
Hi all
I need to insert bullets to a text editor
so I created the following method, which is invoked in the ActionPerformed class
The problem I have is after pressing the enter key the bullet is inserted at the same line, and then the cursor is set to the following next line. But what I want to do is when the enter key is pressed is, first to set the caret to the next line and then insert the bullet
Also when I press the back space key the icon is assigned null, but even then when the enter key is pressed the bullet keeps on appearing. Why is this happening and how to stop this?
Bullet icons are passed as ImageIcons. Is this smthing matters with cleaning the memory?
Can some one please help?
Hi all
I need to insert bullets to a text editor
so I created the following method, which is invoked in the ActionPerformed class
The problem I have is after pressing the enter key the bullet is inserted at the same line, and then the cursor is set to the following next line. But what I want to do is when the enter key is pressed is, first to set the caret to the next line and then insert the bullet
Also when I press the back space key the icon is assigned null, but even then when the enter key is pressed the bullet keeps on appearing. Why is this happening and how to stop this?
Bullet icons are passed as ImageIcons. Is this smthing matters with cleaning the memory?
Can some one please help?
Code:
public static void keyPressed(KeyEvent evt, final ImageIcon ii){
final int width=pane.getDocument().getLength();
pane.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
ImageIcon i=ii;
if(key==KeyEvent.VK_ENTER){
if(i!=null){
pane.insertIcon(i);
return;
}
}
if(key==KeyEvent.VK_BACK_SPACE){
i=null;
}
}
} );
}
Last edited: