• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Resizing JWindow

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Franky D'Souza
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I meant resizing the JWindow by draging the edges with the mouse. This is possible in Frame/JFrame but not in JWindow
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic