• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to stop dragging the JFrame

 
R.Joe
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,I want my JFrame is not moved or draged from the location where i opened the JFrame,it become not movable
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a JWindow instead of a JFrame... there is no title bar, so the user won't be able to move it.
 
R.Joe
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nathan Pruett:
You can use a JWindow instead of a JFrame... there is no title bar, so the user won't be able to move it.


Thanks Sir, 4 replying me, but your solution is not sufficient, i want a window having title bar that why i choose jframe, in that window i don't frame is not resizable not closeable throght close button and not movable for that i use this

setResizable(false);
setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);

this works good but when i try to drag or move this window it shakes that i don't want. could u help me out of this.

[ June 19, 2004: Message edited by: Ravi Lekhwani ]

[ June 19, 2004: Message edited by: Ravi Lekhwani ]
[ June 19, 2004: Message edited by: Ravi Lekhwani ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFrame's are meant to be moved. That's what the title bar, in part, is for. If you don't want it to be dragged there is a few things you can do. None of which you are going to be satisfied with but I will tell you anway.

  • Do what Nathan said and create your own psuedo title bar using a custom JPa nel.
  • Use a window listener to determine when the frame is being dragged and apply a setBounds or setLocation giving it the inital X and Y values so it pops back into place
  • Maximize your app on the screen so the user can't drag it.

  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic