Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

drawing only upper half of word  RSS feed

 
Mark Vermeersch
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In my application I need to draw some formatted words on a JPanel, and only the upper half should be visible. I solved this by writing RTF text on an AAEditorPane, and drawing a rectangle in the background color over half of that AAEditorPane. All this is done within a running thread.

This works fine. The problem is sometimes the rectangle is drawn before the AAEditorPane, although it is invoked later. The code is something like

Any ideas how I can prevent the AAEditorPane from being drawn on top of the rectangle?

Thanks
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rendering that you do with the getGraphics method does not persist,ie, if and when swing decides to repaint your gui/component it will do so and your getGraphics code will not be called. Better to work with swing and subclass JEditorPane and override its paint method (careful, see api) or its paintComponent method.

Or you could create and render your own styled text directly and clip it. You would have to make up some style options for your paint code using Font class methods. Here's some ideas about the clipping part.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!