Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Gradient background on a JSlider

Posted on 2006-07-19
8
Medium Priority
?
910 Views
Last Modified: 2012-05-05
Can I put a gradient background on a JSlider without creating a subClassed JSlider, and if not, how would I need to modify the JSlider to give it a gradient background (Also, both with a background file, and if possible, by just specifying the two end colors?)
0
Comment
Question by:riaancornelius
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 92

Assisted Solution

by:objects
objects earned 1000 total points
ID: 17137747
you'd write a custom ui for your slider

http://blog.elevenworks.com/?p=4
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17137936
awesome tutorial,
and that will definately be handy, but for this specific problem, I need to change only one JSlider and leave all others unchanged...

Thinking about it, It would be quite simple to create a new component and just extend paintComponent, but is there a way to add it onto an existing component without creating a new component?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 1000 total points
ID: 17142419
> I need to change only one JSlider and leave all others unchanged...

u can use different ui for different instances of the same component.

> but is there a way to add it onto an existing component without creating a new component?

yes, by using a custom ui ;)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 26

Expert Comment

by:ksivananth
ID: 17142992
how about developing custom border?
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17143843
>> u can use different ui for different instances of the same component.
That makes sense. Will try that. Thanks Objects.

ksivananth, I need something less subtle than that.
0
 
LVL 3

Expert Comment

by:stimpyjcat
ID: 17156816
Try this AbstractComponentDecorator, which will let you decorate the background of one component at a time:

http://rabbit-hole.blogspot.com/2006/04/decoratingoverpainting-swing.html

Of course, it depends on how much background the original UI leaves to be painted.

Or, you could just wrap it in a JPanel and make the JPanel paint the gradient background.
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 1000 total points
ID: 17156842
to set gradient background to panel,

    class MyPanel extends JPanel{

        public void paintComponent( Graphics g ){
            Graphics2D g2 = (Graphics2D) g;
            g2.setPaint( new GradientPaint((float)   this.getX(),(float) this.getY(), Color.BLUE, (float) this.getX(), (float) this.getY()+ this.getHeight() - 2, Color.WHITE, true));
            g2.fillRoundRect(0,0, this.getWidth(),this.getHeight(), 12, 12);
        }
    }

I feel this is a easiest one!
0
 
LVL 9

Author Comment

by:riaancornelius
ID: 17166373
>> I feel this is a easiest one!
I agree, so I'm using it, but I think objects way is the right way to do it, and I know I'll be using that code in future, so I'm splitting points.
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question