• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Gradient Background for JTextPane

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic