使一组未装饰的选项卡式窗格可移动

Making a setundecorated, tabbedpane movable

我正在为学校做一个项目,遇到了一个小问题。我使用带有 setUndecorated 的框架并添加代码以使用此代码使其可移动:Making a java swing frame movable and setUndecorated

它工作正常,除了我使用选项卡窗格的一帧。

这是一张更好地解释它的图片:

这是我制作 tappedpane 的代码:

    public Main() {

            icon = new ImageIcon(getClass().getResource("usericon.png"));
            icon2 = new ImageIcon(getClass().getResource("aboicon.png"));
            icon3 = new ImageIcon(getClass().getResource("iconcoin.png"));
            icon4 = new ImageIcon(getClass().getResource("icongewicht2.png"));

    JTabbedPane jtbExample = new JTabbedPane();
    JPanel Paneel1 = new Paneel1();                
    jtbExample.addTab("Klanten",icon , Paneel1);

    jtbExample.setSelectedIndex(0);

    JPanel Paneel2 = new Paneel2();
    jtbExample.addTab("Abonnement",icon2, Paneel2);

    JPanel Paneel3 = new Paneel3();
    jtbExample.addTab("Geld opladen",icon3, Paneel3);

    JPanel Paneel4 = new Paneel4();
    jtbExample.addTab("Schema's",icon4, Paneel4);

    // Add the tabbed pane to this panel.
    setLayout(new BorderLayout());
    add(jtbExample);

}


}

提前致谢

您正在将鼠标侦听器添加到 JPanel,在您的情况下,它与 JTabbedPane 重叠。因此,您必须将鼠标侦听器添加到 JTabbedPane。 只需将 f.addMouse(Motion)Listener 替换为 jtbExample.addMouse(Motion)Listener.

    jtbExample.addMouseListener(new MouseListener(){
        public void mouseReleased(MouseEvent e) {
            mouseDownCompCoords = null;
        }
        public void mousePressed(MouseEvent e) {
            mouseDownCompCoords = e.getPoint();
        }
        public void mouseExited(MouseEvent e) {
        }
        public void mouseEntered(MouseEvent e) {
        }
        public void mouseClicked(MouseEvent e) {
        }
    });

    jtbExample.addMouseMotionListener(new MouseMotionListener(){
        public void mouseMoved(MouseEvent e) {
        }

        public void mouseDragged(MouseEvent e) {
            Point currCoords = e.getLocationOnScreen();
            f.setLocation(currCoords.x - mouseDownCompCoords.x, currCoords.y - mouseDownCompCoords.y);
        }
    });