mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.15k stars 235 forks source link

WebComponentPane drag doesn't work when content have mouseListener #531

Open husker-dev opened 5 years ago

husker-dev commented 5 years ago

When I add mouseListener to element's content in WebComponentPane, reordering stops working. Reordering only works using grippers but doesn't work using drag element's content. I think it comes from # 519

WebComponentPane componentPane = new WebComponentPane();
componentPane.setReorderingAllowed(true);
componentPane.addComponentReorderListener((component, i, i1) -> System.out.println("It doesn't work using drag content!"));

componentPane.addElement(new WebPanel(){{
    addMouseListener(new MouseAdapter(){
        public void mouseClicked(MouseEvent e) {
            System.out.println("It works!");
        }
    });
}});

add(componentPane);
mgarin commented 5 years ago

There are possibly two problems in play here:

  1. Reordering uses simple mouse listeners so placing any component that has it's own mouse listener on top of it will block reordering through dragging the component itself. I can't really do much about it because that's how Swing works in general. If you have a panel with mouse listener and a button on top of it covering the whole panel size - panel's mouse listener will never receive any events. You can only workaround it in your custom button mouse listener by manually finding underlying panel and passing an appropriate mouse event to it - I might look into having a simple utility for that.

  2. New hover state actually doesn't use mouse listener to track hover state - it uses global AWT listener for that, so it shouldn't interfere with the reordering. However I will double check that and post an update once I'm completely sure about it.

Also WebComponentPane needs an update at this point, I've added it into the v1.2.11 schedule: #535 - you can track this issue as I will add all updates there (as well as in your specific issues).

mgarin commented 4 years ago

There are some complications I've encountered with this component, so I'll be moving it to v1.2.12 update as it might take some time and I don't want to delay the current update release any further.

mgarin commented 4 years ago

Still working on this in background, but some important changes and fixes will be done to the library first (planned in upcoming v1.3.0 version). WebLaF versioning is also getting adjusted to appropriately reflect changes made in different updates and to allow me to push important fixes outside of larger updates.