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

  • Home
  • SEARCH
  • 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 8930701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:57:07+00:00 2026-06-15T08:57:07+00:00

I’m attempting to implement a changelistener on a JSlider. I’ve tried two separate methods

  • 0

I’m attempting to implement a changelistener on a JSlider. I’ve tried two separate methods neither has worked. The commented out section is the first attempt. The one that’s implemented now would probably be the better suited for my purposes. Can anyone point out what is going wrong with this:

public class MixWindow extends JFrame implements ChangeListener{

    private JPanel contentPane;
    public static int uniA [] = new int [512];
    ChangeListener sizeAction;
    int level = 0;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    MixWindow frame = new MixWindow();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        initUni();
    }

    public MixWindow() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 800, 600);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JSlider slider = new JSlider(0,255);
        slider.setOrientation(SwingConstants.VERTICAL);
        slider.setBounds(66, 275, 72, 140);
        slider.setPaintTicks(true);
        slider.setMajorTickSpacing(20);
        slider.setValue(uniA[0]);
        //slider.addChangeListener(sizeAction);
        contentPane.add(slider);


        final JLabel label = new JLabel("");
        label.setBounds(66, 262, 61, 16);
        contentPane.add(label);


        /*sizeAction=new ChangeListener()
        {
            public void stateChanged (ChangeEvent event)
            {
                System.out.println("This is getting silly");
                JSlider slider=(JSlider)event.getSource();

                level=slider.getValue();
                uniA[0] = level;
                String temp = String.valueOf(level); 
                label.setText(temp);



            }
        };*/
    }

    public static void initUni(){
        for(int i = 0; i < uniA.length; i++){
            uniA[i] = 0;
          }
    }

    @Override
    public void stateChanged(ChangeEvent arg0) {
        // TODO Auto-generated method stub
        System.out.println("Stuff has changed"); 
        Object source = arg0.getSource();
        System.out.println(arg0 + " has Changed");

    }
}
  • 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-15T08:57:09+00:00Added an answer on June 15, 2026 at 8:57 am

    The reason the ChangeListener isn’t working in your 1st approach, is that your listener reference sizeAction is null when you register the listener.

    slider.addChangeListener(sizeAction);
    

    While this won’t throw an exception, it won’t register the listener when it is instantiated.
    Simply alllow this line to appear after you define the listener and it will start working.
    If you wish to use your other ChangeListener implementation instead you can use:

    slider.addChangeListener(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I have an array which has BIG numbers and small numbers in it. I
I've tracked down a weird MySQL problem to the two different ways I was

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.