• Post Reply Bookmark Topic Watch Topic
  • New Topic

cursor gone from custom jtextfield..  RSS feed

 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So i've over-riden jtextfield to make it a bit more prettier and as such the cursor is gone within. How would I go about getting this back?

Thank,

Chris Danch
 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Dancy wrote:So i've over-riden jtextfield to make it a bit more prettier and as such the cursor is gone within. How would I go about getting this back?

Thank,

Chris Danch


That doesn't tell us much really. Post your code or give us more informations (such as what you did exactly to make it look prettier).
 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies...I assumed it was something as easy as setting a variable or something that I had missed... here is the code that i use to override jtextfield's paintComponent()



other that this code, so far everything is the same as normal jtextfield..
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really have to draw the text yourself, or could you just call "super.paintComponent(g)" to do that? I don't see that your rendition of the text adds much value to the default rendition, but perhaps I'm missing something.
 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if I use super.paintComponent() that will mess up the drawing of the component.
 
Brian Cole
Author
Ranch Hand
Posts: 959
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Dancy wrote:if I use super.paintComponent() that will mess up the drawing of the component.


super.paintComponent() will
  • paint the background (unless not opaque)
  • draw the highlighter (text selections and any other highlights)
  • draw the text
  • draw the caret (which is what you mean by cursor)


  • If you choose to do these things yourself, more power to you.

    You can't really expect it to paint the caret automatically if you're drawing the text yourself. How could it position it correctly?
     
    Chris Dancy
    Ranch Hand
    Posts: 136
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    yes how would i go about drawing the carret.
     
    pete stein
    Bartender
    Posts: 1561
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Chris Dancy wrote:if I use super.paintComponent() that will mess up the drawing of the component.

    Why is that? Perhaps you need to fix this bug so that you can call this important method rather than try to create a kluge.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!