JPanel verschieben

ChMaster

Mitglied
Hallo zusammen,

habe da mal wieder ein kleines Problem. Diesmal geht es ums verschieben verschiedener JPanels. Mein Problem ist nun, wenn ich ein JPanel vergrössere verliert mein JPanel den Fokus und und die Grösse bleibt gleich. Beim verkleinern geht es wunder bar.

Hier nun ein kleiner Codeausschnitt aus meinem Programm:
Hier wird der entsprechende Courser gesetzt (Hand, N_Resize, .....).
Code:
    public void setApplicableCursor( Point cursorPosition )
    {
        Rectangle bounds = getBounds();

        if ( isMarked() )
        {
            if ( resizeObject( cursorPosition.x, cursorPosition.y, bounds.width, bounds.height ) )
                setCursor( new Cursor( Cursor.SE_RESIZE_CURSOR ) );

            else if ( cursorPosition.y >= 0 && cursorPosition.y <= 5 )
                setCursor( new Cursor( Cursor.N_RESIZE_CURSOR ) );

            else if ( cursorPosition.x <= bounds.width && cursorPosition.x >= bounds.width - 5 )
                setCursor( new Cursor( Cursor.E_RESIZE_CURSOR ) );

            else if ( cursorPosition.y <= bounds.height && cursorPosition.y >= bounds.height - 5 )
                setCursor( new Cursor( Cursor.S_RESIZE_CURSOR ) );

            else if ( cursorPosition.x >= 0 && cursorPosition.x <= 5 )
                setCursor( new Cursor( Cursor.W_RESIZE_CURSOR ) );

            else
                setCursor( new Cursor( Cursor.HAND_CURSOR ) );
        }
        else
            setCursor( new Cursor( Cursor.DEFAULT_CURSOR ) );
    }
Und hier wird das objekt (JPanel) vergrössert/verkleinert), beim vergrössern gibt es wie oben beschrieben das Problem.
Code:
    public void mouseDragged( MouseEvent me )
    {
        Point dragDestination = SwingUtilities.convertPoint( this, me.getPoint(), this.getParent() );
        Point dragDifference = new Point( dragDestination.x - dragSource.x, dragDestination.y - dragSource.y );

        if ( ( ( LayoutPanel ) this.getParent() ).getMarkedObjects().size() > 1 )
            LayoutPanel.setAllObjectsUnmarked( this.objectId );

        switch( getCursor().getType() )
        {
            case Cursor.HAND_CURSOR:
                origin = new Point( origin.x + dragDifference.x, origin.y + dragDifference.y );
                dragSource = dragDestination;
                setLocation( origin );
                break;
            case Cursor.N_RESIZE_CURSOR:
                this.setBounds( this.getBounds().x, this.getBounds().y + dragDifference.y, this.getSize().width, this.getSize().height + ( dragDifference.y * -1 ) );
                dragSource = dragDestination;
                break;
            case Cursor.E_RESIZE_CURSOR:
                this.setSize( this.getSize().width + dragDifference.x, this.getSize().height );
                dragSource = dragDestination;
                break;
            case Cursor.S_RESIZE_CURSOR:
                this.setSize( this.getSize().width, this.getSize().height + dragDifference.y );
                dragSource = dragDestination;
                break;
            case Cursor.W_RESIZE_CURSOR:
                this.setBounds( this.getBounds().x + dragDifference.x, this.getBounds().y, this.getSize().width + ( dragDifference.x * -1 ), this.getSize().height );
                dragSource = dragDestination;
                break;
            case Cursor.SE_RESIZE_CURSOR:
                int ne_x = this.getBounds().x;
                int ne_y = this.getBounds().y;
                int ne_width = this.getSize().width + dragDifference.x;
                int ne_height = this.getSize().height + dragDifference.y;

                this.setBounds( ne_x, ne_y, ne_width, ne_height );

                dragSource = dragDestination;
                break;
        }

        ( ( LayoutPanel ) this.getParent() ).setParentScale( SwingUtilities.convertPoint( this, me.getPoint(), this.getParent() ) );
    }
 
Servus zusammne,

ich habe bis jetzt noch keine Lösung finden können. Hat keiner von euch einen Tip für mich was ich da falsch mache?
 
danke, es hat sich erledigt.

der fehler war das ich im mouseExited(..) eine funktion zu viel hatte. die hat nix anderes
gemacht als den cursor auf das JPanel zu setzen. habe diesesn einzeiler nur durch
setCursor( new Cursor( Cursor.DEFAULT_CURSOR ); ersetzt und siehe da es funktioniert.

der obenstehende quellcode funktioniert.
 
Zurück