Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

cursor gone from custom jtextfield..  RSS feed

 
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
 
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..
 
Sheriff
Posts: 23582
48
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.
 
Author
Ranch Hand
Posts: 964
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.
     
    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.
     
    moose poop looks like football shaped elk poop. About the size of this tiny ad:
    Why should you try IntelliJ IDEA ?
    https://coderanch.com/wiki/696337/IntelliJ-IDEA
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!