File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Resizing JWindow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Resizing JWindow" Watch "Resizing JWindow" New topic
Author

Resizing JWindow

Franky D'Souza
Greenhorn

Joined: Mar 20, 2001
Posts: 5
I would like to get some help on resizing a JWindow.I believe it is possible by trapping mouse events, but it will take some time to write the code, if anyone has done this already plz. mail me the code or give me some kind of help to get this done fast..
Daniel Searson
Ranch Hand

Joined: Dec 03, 2000
Posts: 83
Could you be a bit more specific? If you need to resize the window, use setSize(). If you need to know when the window is being resized, add a component listener like:
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
// do whatever here
}
});
The width and height of the window can be retrieved with getWidth() and getHeight() I believe.


- Daniel
Franky D'Souza
Greenhorn

Joined: Mar 20, 2001
Posts: 5
Actually I meant resizing the JWindow by draging the edges with the mouse. This is possible in Frame/JFrame but not in JWindow
Buckley Lee
Greenhorn

Joined: Mar 28, 2001
Posts: 19
Actually, this is possible using a JWindow, I've done it before. However, the result it NOT as nice as dragging a JFrame/Frame. Here's how you do it: add a mouseMotionListener (for mouseDragged and mouseMoved events). Inside of the mouseDragged event you simply redraw the JWindow according to the new mouse position. I also added a mouseListener, and inside of the mousePressed event retrieved where the mouse was initially clicked inside the window. You can re-draw the window and keep the mouse cursor at the same position in the window where it was initially clicked.
This has a somewhat sparodic behavior though, in that the dragging of the JWindow sometimes redraws in locations where the mouse has not been dragged. It's an annoying problem that I have yet to solve. It's as if there is a problem reporting where the mouse cursor is, or that the redraws are not keeping up with the mouse movement. I modified the code to use double buffering for the dragging to make it smoother, but that didn't really help either. I'm currently looking into how to make the dragging smoother. I'll keep you updated if I get it working better.
I believe the dragging of a JFrame/Frame is handled by the operating system, whereas (since there is no title bar) the dragging of a JWindow has to be handled by the Java code, which is SLOWER than the operating system.
 
 
subject: Resizing JWindow