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 864559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:29:54+00:00 2026-05-15T09:29:54+00:00

I am trying to set some actions on a custom ListSelectionListener and although everything

  • 0

I am trying to set some actions on a custom ListSelectionListener and although everything compiles out fine when I actually select a component of the jList it’s not working.

Here’s a code snippet:

public class ListSelectionHandler implements ListSelectionListener
{
    ListCustomObject o;

    @Override
    public void valueChanged(ListSelectionEvent e)
    {
            o = (ListCustomObject) app.MainWindow.jList1.getModel()
                    .getElementAt(e.getFirstIndex());

            new app.actions.Actions().createSetEdgeColorTo(o.getColor());
    }

}

The action I am calling, is working and there’s no error when compiling. But nothing actually happens.

I know I am not including much detail in this code, I just wanna ask if I am making a logical mistake in this event.

Thanks in advance!

EDIT: Added the Action and the JList initialization:

    public Action createSetEdgeColorTo(Color color)
    {
        return new SetEdgeColorTo(color);
    }

    class SetEdgeColorTo extends AbstractAction
    {

        Color color;

        SetEdgeColorTo(Color color)
        {

            super("Set new Edge Color");
            this.color = color;
        }

        @Override
        public void actionPerformed(ActionEvent evt)
        {
            app.graph.GraphEdit.view.getGraph2D().getDefaultEdgeRealizer()
                                                 .setLineColor(color);
            app.graph.GraphEdit.view.getGraph2D().updateViews();
        }
    }

and

JList jList1 = new javax.swing.JList();
ListSelectionModel listSelectionModel = jList1.getSelectionModel();
listSelectionModel.addListSelectionListener(new app.jlist
                                             .ListSelectionHandler());

EDIT 3: Reworked SSCCE:

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.Action;
import javax.swing.JFrame;

public class SSCCE
{

    static JList jList1;

    public static void main(String[] args)
    {

        JFrame frame = new JFrame();
        jList1 = new JList();
        ListSelectionModel listSelectionModel = jList1.getSelectionModel();
        listSelectionModel.addListSelectionListener(
                new ListSelectionHandler());
        DefaultListModel listModel = new DefaultListModel();
        jList1.setModel(listModel);
        listModel.addElement("String");
        listModel.addElement("String two");

        frame = new JFrame();
        frame.setDefaultCloseOperation(1);
        frame.add(jList1);
        frame.pack();
        frame.setVisible(true);

    }
}

class ListSelectionHandler implements ListSelectionListener
{
    @Override
    public void valueChanged(ListSelectionEvent e)
    {

        System.out.println("" + e.getFirstIndex());
        new Actions().createTestAction();
    }
}

class Actions
{

    public Action createTestAction()
    {
        return new TestAction();
    }

    class TestAction extends AbstractAction
    {

        TestAction()
        {
            super("Test Action");
        }

        @Override
        public void actionPerformed(ActionEvent evt)
        {
            System.out.println("Test Action Fired!");
        }
    }
}

This SSCCE describes the exact problem with a sample TestAction that again is not firing.

  • 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-05-15T09:29:54+00:00Added an answer on May 15, 2026 at 9:29 am

    So what exactly are you trying to do?

    If you are trying to set the color of a row that has been selected, then that code should be done in the renderer. In general whenever you play with colors in a renderer you need the check:

    if (! isSelected)
        //  do you custom rendering
    

    This way the row will still show the default highlighting as you select different rows.

    And of course a SSCCE should still be posted because we have no idea what your custom Action is attempting to do and therefore can’t make any real suggestions.

    Edited:

    It doesn’t do anything because all your code is doing is creating the Action. If you want to invoke the Action then the code should be something like:

    new Actions().createTestAction().actionPerformed(null);
    

    In reality there is no need to create an actual Action, you just need to invoke some method directly that does what you want. The reason you create an Action would be if you wanted to add the Actdion to a JButton or JMenuItem so the user could click on the component to invoke the Action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm playing around with Rhino Mocks and am trying to set some dummy results
I'm trying to write a shell script that, when run, will set some environment
I'm trying to set up AutoHotkey macros for some common tasks, and I want
i'm trying to set up the selenium-maven-plugin and having some difficulties i hope somebody
I'm having some minor problems with some animations I'm trying to set up. I
I'm trying to automate some stuff in MS Excel. When I try to set
Where would set_include_path(../../); point to? I am trying to run some PHP code on
I am trying set up databinding as described in the title. The problem I
Trying to set up caching on our datasets - we're using clr stored procedures
Im trying to set up a session and i am getting a header error,

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.