Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7993895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:59:20+00:00 2026-06-04T13:59:20+00:00

I am using the visual design editor in Netbeans. I have two sliders with

  • 0

I am using the visual design editor in Netbeans. I have two sliders with corresponding JLabels. What I want is a rectangle that changes color when the slider is moved. How do I incorporate this with the designer’s generated code?

How do I paint my rectangle near the slider?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:59:22+00:00Added an answer on June 4, 2026 at 1:59 pm

    Colors in Java are composed by RGBvalues.

    Color c = new Color(red, green, blue)
    

    Red, Greenand Blue all have integer values between 0 and 255. Netbeans visual editor allows you to set both maximum and minimum values for your slider.

    To add transparency to a color use

    Color c = new Color(red, green, blue, alpha)
    

    Red, Green, Blue and Alphaall have float values between 0.0 and 1.0.

    To change color when the slider is moved, add an event for when the mouse is dragged (you can do this using the visual editor) and use slider.getValue() to retrieve the value.

    To paint the rectangle near the sliders (there should be at least 3 sliders, one for each rbg component) retrieve the slider position and dimensions with slider.getBounds() (bounds contains x and y coordinates plus width and height)

    Example (draws a rectangle 30×30 20 pixels right the sliders)

    private void mouseDragged(java.awt.event.MouseEvent evt) {
    
        color = new Color(sliderRed.getValue(), sliderGreen.getValue(), sliderBlue.getValue());
        this.repaint();
    }
    
    public void paint(Graphics g) {
    
        g.setColor(color)
        g.fillRect(sliderRed.getBounds().x + sliderRed.getBounds().width + 20, sliderRed.getBounds().y, 30, 30);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While working with SilverLight using Visual Studio 10, I found that in design mode
I have a Microsoft Access 2010 database(*). Now, using Visual Studio 2010, I want
I'm using Visual Studio 2005. I normally use the DataSet Editor to design datasets.
I am using Visual C# 2008 Express edition. If at design time I have
I want to create a JTabbedPane in a Visual Class using the Visual Editor
Using Visual Studio 2005, I wrote a simple DLL in C that uses the
(Using Visual Studio 2005 / .NET 2.0) I have a DataSet which is being
I am using Visual Studio 2008 and all the components that come with it
I am new to LINQ. I am using Visual Studio 2008 and have created
im using mvc framework and i have learned some techniques that help me with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.