• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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: 79701
381
  • 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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic