0

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

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

这是一个更好地解释它的图像: http://gyazo.com/6cea08f42347841a3846bdfffe9e3d71

这是我制作 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);

}


}

提前致谢

4

1 回答 1

1

您正在将鼠标侦听器添加到 JPanel,在您的情况下,它与 JTabbedPane 重叠。因此,您必须将鼠标侦听器添加到 JTabbedPane。只需将 替换f.addMouse(Motion)ListenerjtbExample.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);
        }
    });
于 2015-03-07T14:18:00.137 回答