• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Gradient Background for JTextPane

 
sachin upatil
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want Gradient Color background for JTextPane....

I tried this.



in this code gradient is working fine. But JTextPane is not showing any Text on it.

What is wrong with this code ?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What on earth does screen = JTextPane() { . . . mean? Have you got a method of that name or are you trying to create an anonymous class? In either case it looks as though you have a compiler error in it.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:What on earth does screen = JTextPane() { . . . mean? Have you got a method of that name or are you trying to create an anonymous class? In either case it looks as though you have a compiler error in it.


Yep, and "color". To the OP, please post real code.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyway, one solution is to put the JTextPane into a JScrollPane and set the gradient of the JViewport that holds the JTextPane. If you do this be sure to set the JTextPane's opaque property to false. Oh, and you probably want to avoid using null layout and setBounds.

For example:
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pete's solution is good, but "fixes" the gradient background i.e. the background gradient won't scroll with the text pane.

It's sufficient to setOpaque(false) and paint the text pane's background before invoking the super implementation.To the OP: note that constructing a GradientPaint is computationally expensive and you are likely to see a surge in CU use during periods of frequent repainting, or even a slowdown and flickering/jerks on an older, slow computer.
 
sachin upatil
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic