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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:58:48+00:00 2026-05-22T17:58:48+00:00

I have a JTree where users can drop elements from other components. When the

  • 0

I have a JTree where users can drop elements from other components. When the users hovers over nodes in the tree (during “drop mode”) the most near lying node is highlighted. This is achieved in the implementation of TransferHandler.

@Override
public boolean canImport(TransferSupport support) {

    //Highlight the most near lying node in the tree as the user drags the 
    //mouse over nodes in the tree.
    support.setShowDropLocation(true);

Each time a new node is selected (also during “drop mode”), this will kick of a TreeSelectionEvent. This in turn will invoke a listener i have created which will query a database for details related to that node.

Now, I am looking for a way to somehow filter out events that is generated from node selections during “drop mode”. It is an attempt to limit database calls. Does anyone have any ideas about how I can achieve this?

All input will be highly appreciated!

  • 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-22T17:58:49+00:00Added an answer on May 22, 2026 at 5:58 pm

    There is a very indirect method to detect this case. You may register a PropertyChangeListener on the property "dropLocation" with the tree component. This will be called whenever the drop location changes and thus you can set a field dropOn there which you then can read in the TreeSelectionListener.

    tree.addPropertyChangeListener("dropLocation", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            dropOn = pce.getNewValue() != null;
        }
    });
    
    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent tse) {
            System.out.println(tse + " dropOn=" + dropOn);
        }
    });
    

    Note that this does fire a wrong false value for the first time it enters the tree, but all subsequent events then show dropOn = true.

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

Sidebar

Related Questions

I have a JTree in which the user can drag/drop or re-arrange nodes, upon
I have a Jtree with nodes representing images that the user can call up
I have a JPanel panel which contains a JTree tree . Sometimes the JTree
I have a enumeration for elements in a JTree When I find some specific
I have a JTree which displays a JPopupMenu when I right click nodes in
I have a JTree and the Nodes are a abstract class (Item) that extends
I have a class derived from JTree with custom TreeCellRenderers. I have implemented drag
I'm writing a Java Tree in which tree nodes could have children that take
I have a large JTree and I need to expand thousands of nodes all
I'm trying to use dynamically JTree component. Under root node I have four nodes

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.