How to set the caret to the next new line

acu

Joined
May 12, 2009
Messages
2
Reaction score
0
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?



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:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top