Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

moving a JWindow

 
Barry Andrews
Ranch Hand
Posts: 523
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Does anyone know how I can move a JWindow at runtime? I want to use JWindow because I do not want the title bar. Do I need to hook up a listener or what? Also, is there a way to set up some kind of border on a JWindow? Thanks for your help!

Barry
 
paul wheaton
Trailboss
Pie
Posts: 21598
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use setLocation() - works like a charm!
 
Barry Andrews
Ranch Hand
Posts: 523
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, no, no........ Sorry about the confusion. I meant the user moving the window. Since it has no title bar, a user cannot move it. So, is there a way to fix this?
Thanks,
Barry
 
Noah Carroll
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to do it is to implement a mouse motion listener to either the entire window or a component within the window. Then when the user clicks and drags on that part you can have the entire window move to the new location. It is quite simple code. I have done it before, but it is on a different comp. I will post it tonight unless someone else does.
------------------
I hope its helps, feel free to email me noahcarroll@juno.com
 
Barry Andrews
Ranch Hand
Posts: 523
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I will hook the listener up to the JWindow itself. That will be the best way. Thanks!
 
Noah Carroll
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry, here is the code that I used a while back in one of my applications. It is concise and works great. Just use the handler for your mousemotion.
<PRE>
class MouseMotionHandler extends MouseMotionAdapter {
public void mouseDragged(MouseEvent e) {
window.setLocation(
window.getLocationOnScreen().x - (p.x - e.getX()),
window.getLocationOnScreen().y - (p.y - e.getY()));
}
}
</PRE>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic