Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cursor in JTextPane  RSS feed

 
kumar mars
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai
i have a JTextPane. A JButton is inserted in the JTextPane using insertComponent() method.
i want the cursor to be changed to HAND_CURSOR when it is over the button.
i added a mouselistener to the button. In the listener i implemented the method mouseEntered(). In this method i used setCursor() to set the cursor but the cursor is not getting changed. someboby pl help
And is there is way of inserting an URL in JTextPane??
Thanks in anticipation
bye
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i tried this and was able to get it working ..
i dont know what u have done,but here the code which is working and was able to change the Cursor ,once it was on a button.
take a look at it... as for the second part, i hadnt tried it.i will take a look at it..
import java.awt.*;
import java.awt.event.*;
import javax.swing .*;
public class textpane extends JFrame
{
JTextPane textpane;
JButton button;
Container cont;
textpane()
{
cont = getContentPane();
cont.setLayout(new FlowLayout());
textpane = new JTextPane();
button = new JButton("added to textpane");
textpane.insertComponent(button);
button.addMouseListener(new mouselistener());
cont.add(textpane);
System.out.println(Cursor.HAND_CURSOR); // 12
System.out.println(Cursor.N_RESIZE_CURSOR); //8
}
class mouselistener extends MouseAdapter
{
public void mouseEntered(MouseEvent me)
{
Cursor c = new Cursor(8);
button.setCursor(c);
}
}

public static void main(String a[])
{
textpane tp = new textpane();
tp.setSize(300,300);
tp.setVisible(true);
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!