Java makes JFrame "abandoned"

Is there a way to make the frame of a Java application stay where I show it with .setLocation? I want to disable its ability to navigate the screen by the user.

+4
source share
4 answers

This is how you prevent JFrame from moving. It is not recommended to use this in a production application, because it will work with users and will cause other errors when the user tries to set the minimum / maximum frame.

public static void main(String args[]) throws Exception { class JFrameTypeLocking extends JFrame { Point locked=null; public JFrameTypeLocking(String string) { super(string); super.addComponentListener(new ComponentAdapter(){ public void componentMoved(ComponentEvent e) { if (locked!=null) JFrameTypeLocking.this.setLocation(locked); }}); } public void lockLocation() { locked=super.getLocation(); } } JFrameTypeLocking f = new JFrameTypeLocking(""); f.setSize(300,300); f.setLocation(300,300); f.setVisible(true); f.lockLocation(); } 
+3
source

Can you create a daemon thread that checks if the frame is moving, and if it is placed where it was?

+3
source

You cannot “block” JFrame movement. This is part of the system graphical interface; the best you can do is add a ComponentListener to the JFrame and return it to its original location when moving it.

I think the visuals are pretty funny at the same time.

+2
source

This is a bit of a hack, but you can make it fullscreen. Unable to move full screen application.

0
source

Source: https://habr.com/ru/post/1401456/


All Articles