how to set up an rgb slider using java.awt?

L

Lee Davidson

Simple task: use Scrollbars for red, green, and blue color components.

My red scrollbar should be W pixels wide, horizonal, min = 0, max =
255, visible = 1, and all that.

I thought the constructor call would be Scrollbar( style, value,
visible, min, max ); When I try

sb = new Scrollbar( Scrollbar.HORIZONTAL, 0, 1, 0 255 );

I get a trivial scrollbar of almost no length, and, anyway, I don't
see any control for the pixel width of the thing.

My Sun documentation shows a picture of a Scrollbar

ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 60, 0, 300);

and it looks reasonable. But when I put in this exact code I only get
a trivial Scrollbar like before.

What, exactly, am I missing here? This simply cannot be this
difficult.

So, what am I missing here?
 
D

Daniele Futtorovic

Simple task: use Scrollbars for red, green, and blue color components.

My red scrollbar should be W pixels wide, horizonal, min = 0, max =
255, visible = 1, and all that.

I thought the constructor call would be Scrollbar( style, value,
visible, min, max ); When I try

sb = new Scrollbar( Scrollbar.HORIZONTAL, 0, 1, 0 255 );

I get a trivial scrollbar of almost no length, and, anyway, I don't
see any control for the pixel width of the thing.

My Sun documentation shows a picture of a Scrollbar

ranger = new Scrollbar(Scrollbar.HORIZONTAL, 0, 60, 0, 300);

and it looks reasonable. But when I put in this exact code I only get
a trivial Scrollbar like before.

What, exactly, am I missing here? This simply cannot be this
difficult.

So, what am I missing here?

The problem is probably with your LayoutManager.

Try posting a Short, Self-Contained, Compilable Example.
 
R

Roedy Green

What, exactly, am I missing here? This simply cannot be this
difficult.

Sliders did not come into being until Swing. To see how I did my
colour chooser in AWT see
http://mindprod.com/applet/fontshowerawt.html

Given that even Java 1.5 is no longer supported, there is little
motive to write new code in AWT.

--
Roedy Green Canadian Mind Products
http://mindprod.com
Refactor early. If you procrastinate, you will have
even more code to adjust based on the faulty design.
..
 
I

Ian Shef

The problem is probably with your LayoutManager.

Try posting a Short, Self-Contained, Compilable Example.
I second this suggestion, and add:

A Scrollbar is a Component, and inherits many methods (and corresponding
properties) from Component, including minimumSize, maximumSize, and
preferredSize (yes, I know that these specific method names are deprecated,
but it doesn't change the issue).

You need to set these properties, or use a Container with an appropriate
LayoutManager. Some LayoutManager_s are better (in some sense) at
respecting these properties than others.

SSCCE, please!
 
L

Lawrence D'Oliveiro

In message
Simple task: use Scrollbars for red, green, and blue color components.

Just wondering, are you offering any alternative way to set colours, such as
HSV?

Just that RGB is not an easy way for users to choose colours.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top