Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/06/2009, 18:29
decoArguello
 
Fecha de Ingreso: marzo-2009
Ubicación: Santa Marta
Mensajes: 73
Antigüedad: 15 años, 9 meses
Puntos: 2
Respuesta: JFrame Personalizado

si de algo sirve aun..

con este codigo que encontre en algun foro hace tiempo podras mover tu componente.. disculpas al autor.

Código:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package PruebasGUI;

import java.awt.Container;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JComponent;
import javax.swing.JFrame;


public class MoveMouseListener implements MouseMotionListener, MouseListener {
    JComponent target;
    Point start_drag;
    Point start_loc;
    public MoveMouseListener(JComponent target) {
        this.target = target;
    }
    public static JFrame getFrame(Container target) {
    if (target instanceof JFrame) {
      return (JFrame) target;
    }
    return getFrame(target.getParent());
  }

  Point getScreenLocation(MouseEvent e) {
    Point cursor = e.getPoint();
    Point target_location = this.target.getLocationOnScreen();
    return new Point((int) (target_location.getX() + cursor.getX()),
        (int) (target_location.getY() + cursor.getY()));
  }
    public void mouseDragged(MouseEvent e) {
        Point current = this.getScreenLocation(e);
        Point offset = new Point((int) current.getX() - (int) start_drag.getX(),(int) current.getY() - (int) start_drag.getY());
        JFrame frame = getFrame(target);
        Point new_location = new Point((int) (this.start_loc.getX() + offset.getX()), (int) (this.start_loc.getY() + offset.getY()));
        frame.setLocation(new_location);
    }

    public void mouseMoved(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseClicked(MouseEvent e) {
       // throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mousePressed(MouseEvent e) {
        this.start_drag = this.getScreenLocation(e);
        this.start_loc = getFrame(this.target).getLocation();
    }

    public void mouseReleased(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseExited(MouseEvent e) {
       // throw new UnsupportedOperationException("Not supported yet.");
    }

}
y un la aplicacion seria de la siguiente manera

Código:
        MoveMouseListener mml = new MoveMouseListener(jLabel1);
        jLabel1.addMouseListener(mml);
        jLabel1.addMouseMotionListener(mml);
es decir que con ese label podras mover tu frame tranquilamente

espero te sirvaaaa