Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix a JFrame to a specific position?

How can I set my JFrame to a specific psotion on the screen? I've already managed to fix its size. I want it to be at a standard location on the screen and not be moved by the user.

like image 862
user3760399 Avatar asked Dec 05 '25 15:12

user3760399


1 Answers

You can fixate it as follows:

frame.setResizable(false);
frame.setUndecorated(true);

Or better: by adding a Component listener:

frame.addComponentListener( new ComponentListener() {
      public void componentResized( ComponentEvent e ) {}
      public void componentMoved( ComponentEvent e ) {
         setLocation( FIX_X, FIX_Y );
      }
      public void componentShown( ComponentEvent e ) {}
      public void componentHidden( ComponentEvent e ) {}
 } );
like image 105
sina72 Avatar answered Dec 07 '25 04:12

sina72