javaswingframejtabbedpanemovable

Making a setundecorated, tabbedpane movable


I'm making a project for school and having a little problem. I used frames with setUndecorated and added code to make it movable using this: Making a java swing frame movable and setUndecorated

It works fine except for one frame where I am using a tabbedpane.

Here's an image explaining it better: http://gyazo.com/6cea08f42347841a3846bdfffe9e3d71

Here is my code where I make the 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);

}


}

Thanks in advance


Solution

  • You´re adding the Mouse-Listeners to the JPanel, which in your case is overlapped by the JTabbedPane. Therefore you have to add the Mouse-Listeners to the JTabbedPane. Just replace the f.addMouse(Motion)Listener with 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);
            }
        });