drag java undecorated window

Just for reminder,

“How to drag undecorated window”
place a JLabel or what ever component which does support mouse mototion and mouse event listener.

undecorated window: when window is head less. no caption bar no resizable border. is enabled by  setUndecorated( true );

private boolean mMoveStart = false;
private Point mMouseClickPoint = null;
private void _setUpMoveEvent() {
mWindowTitleLabel.addMouseMotionListener(
new MouseMotionListener() {
public void mouseDragged(MouseEvent mouseEvent) {
if (mMoveStart)
_moveWindowTo(mouseEvent.getPoint());
}

public void mouseMoved(MouseEvent mouseEvent) {

}

}
);
mWindowTitleLabel.addMouseListener(
new MouseAdapter() {
public void mousePressed(MouseEvent mouseEvent) {
mMouseClickPoint = mouseEvent.getPoint();
mMoveStart = true;
}

public void mouseReleased(MouseEvent mouseEvent) {
mMoveStart = false;
_fireStickyUpdated();
}
}
);
}

private void _moveWindowTo(Point point) {
int musDiffX = point.x - mMouseClickPoint.x;
int musDiffY = point.y - mMouseClickPoint.y;

setLocation( getLocation().x + musDiffX, getLocation().y + musDiffY );
sticky.setLocation( getLocation() );
}

here, mWindowTitleLable is JLable component

:D

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

my tweets

 

September 2006
S S M T W T F
« Aug   Oct »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Flickr Photos



@kamalapur over bridge

@kamalapur station

cox's bazaar trip oct 09

cox's bazaar trip oct 09

More Photos
Follow

Get every new post delivered to your Inbox.