To have a JFrame without customization to change the taskbar

I need to have a JFrame, which when I change the size or position of the window taskbar, the frame does not have to be adjusted by itself. Which JFrame method will be called exactly when the size and position of the taskbar are changed? Which method do I need to cancel?

To put it more clearly, By default, the JFrame instance will itself change its height and width when I change the size and position of the window taskbar. But my JFrame should not react when I expand the window taskbar or when I change the taskbar from horizontal to vertical. It should remain in default state.

0
source share
2 answers

Using setResizable(false); Example:

 import javax.swing.JFrame; public class JavaApplication7 extends JFrame{ public static void main(String[] args) { JFrame frame = new JFrame("EG"); frame.setVisible(true); frame.setResizable(false); } } 

This creates a small JFrame named "EG" that cannot be changed.

0
source

I do not think this is impossible to prevent. It does not seem to call setBounds or setLocation or setSize, but rather moves the window directly at the OS level. The best you can probably do is to detect border changes using a ComponentListener, and then immediately return the window to where you want.

 final Rectangle fixedPosition = new Rectangle(...); frame.setBounds(fixedPosition); frame.addComponentListener(new ComponentListener() { public void componentMoved(ComponentEvent e) { if (!frame.getBounds().equals(fixedPosition)) { frame.setBounds(fixedPosition); } } public void componentResized(ComponentEvent e) { componentMoved(e); } public void componentShown(ComponentEvent e) {} public void componentHidden(ComponentEvent e) {} }); 
0
source

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


All Articles