How to deactivate right-click menu? (Common)

First of all, congratulations on doing and maintaning such an impressive framework.

I’ve been fiddling around with Common, seeing if we might incorporate it in one of our applications, but I haven’t been able to get the right-click pop up menus on tabs to deactivate. Since the panels/components we are going to use have their own, defined pop up menu, I would like to make it so the Docking Frames action pop up menu (with minimize, maximize, etc…) only pops up if the tab itself is right clicked, but allow the contents of the dockable to handle the right click themselves, without any interaction from Docking Frames.

Is that possible to do? I’m using 1.0.7 at the moment. Thanks in advance!

The popup should show up only if a MouseEvent falls through to a Dockable. Just adding a MouseListener to a Component (e.g. the one Container that takes up all the space on your Dockable) should be enough to prevent that from happening.

I don’t have a 1.0.7 at hand (its quite old, I really suggest you upgrade to 1.0.8, the stable release is available in less than a week), but the example below should work. No popups to see when you click the red or green areas.


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;

import javax.swing.JFrame;
import javax.swing.JPanel;

import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CLocation;
import bibliothek.gui.dock.common.DefaultSingleCDockable;

public class Dock21 {
    public static void main( String[] args ){
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        CControl control = new CControl(frame);

        frame.add(control.getContentArea(), BorderLayout.CENTER);
        frame.setSize(new Dimension(700, 700));
        frame.setLocationRelativeTo(null);

        DefaultSingleCDockable red = create(control, "Red", Color.RED);
        DefaultSingleCDockable green = create(control, "Green", Color.GREEN);

        control.add(red);
        control.add(green);

        red.setLocation(CLocation.base().normal());
        green.setLocation(CLocation.base().normal().south(0.5));

        red.setVisible(true);
        green.setVisible(true);

        frame.setVisible(true);
    }

    public static DefaultSingleCDockable create( CControl control, String title, Color color ){
        JPanel panel = new JPanel();
        panel.setOpaque(true);
        panel.setBackground(color);

        // With this line, no MouseEvents fall through and no popup shows up
        panel.addMouseListener(new MouseAdapter(){
        });

        final DefaultSingleCDockable singleDockable = new DefaultSingleCDockable(title, title, panel);

        return singleDockable;
    }
}```

Tested that, it works. Thanks!

And if there’s a stable release coming soon, then I’ll probably use 1.0.8 instead. The tip is well appreciated!