• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cursor in JTextPane

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
}
reply
    Bookmark Topic Watch Topic
  • New Topic