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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:27:02+00:00 2026-05-22T01:27:02+00:00

If you have JTable set with table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) and then you click drag on a

  • 0

If you have JTable set with table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) and then you click drag on a row that is not already selected, it starts selecting multiple rows. We don’t want that behavior. We want it so if you click on a node, even if it’s not already selected, it will start dragging it.

We do need the multi select mode on, so setting it to single select (which does result in the behavior we want) is not an option.

Update: At this point, it appears it will require some type of ugly hack since the logic is in a private method BasicTableUI$Handler.canStartDrag

  • 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-22T01:27:03+00:00Added an answer on May 22, 2026 at 1:27 am

    I found one possible solution. You bracket the mouse listeners so you can lie to the call to isCellSelected during the canStartDrag call.

    Subclass JTable (or in my case, JXTreeTable). In the constructor call this:

    private void setupSelectionDragHack()
    {
        // Bracket the other mouse listeners so we may inject our lie
        final MouseListener[] ls = getMouseListeners();
        for (final MouseListener l : ls)
        {
            removeMouseListener(l);
        }
        addMouseListener(new MouseAdapter()
        {
            @Override
            public void mousePressed(final MouseEvent e)
            {
                // NOTE: it might not be necessary to check the row, but... I figure it's safer maybe?
                mousingRow = rowAtPoint(e.getPoint());
                mousingInProgress = true;
            }
        });
        for (final MouseListener l : ls)
        {
            addMouseListener(l);
        }
        addMouseListener(new MouseAdapter()
        {
            @Override
            public void mousePressed(final MouseEvent e)
            {
                mousingInProgress = false;
            }
        });
    }
    

    And then you’ll need this:

    @Override
    public boolean isCellSelected(final int row, final int column)
    {
        if (mousingInProgress && row == mousingRow)
        {
            // Only lie to the canStartDrag caller. We tell the truth to everyone else.
            final StackTraceElement[] elms = Thread.currentThread().getStackTrace();
            for (int i = 0; i < 3; i++)
            {
                if (elms[i].getMethodName().equals("canStartDrag"))
                {
                    return mousingInProgress;
                }
            }
        }
        return super.isCellSelected(row, column);
    }
    

    It’s an ugly hack in many ways, but… for now it seems to work.

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

Sidebar

Related Questions

I have a jtable, everything works fine if I set the table data as
I have a custom cell renderer set in JTable and it works but instead
I have this JTable on my Swing app with the autoCreateRowSorter enabled. My table
I have a JTable with a custom TableModel called DataTableModel . I initialized the
The problem is quite basic. I have a JTable showing cached data from a
I'm having small problem (I guess) of showing the JTable panel. I have class
I have a table with 3 columns which have the following values in the
I am putting a JTable into a JScrollPane But When I set JTable Auto
I have a JScrollPane with a JTable in it. In the JTable I have
I have to limit the number of rows in a JTable . If I

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.