aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Gradient Background for JTextPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Gradient Background for JTextPane" Watch "Gradient Background for JTextPane" New topic
Author

Gradient Background for JTextPane

sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
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

Joined: Oct 13, 2005
Posts: 39400
    
  28
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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: Feb 23, 2007
Posts: 1561
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

Joined: May 03, 2008
Posts: 4642
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
sachin upatil
Greenhorn

Joined: May 17, 2010
Posts: 29
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Gradient Background for JTextPane