Why does the appearance and appearance of the face affect the resizing?
Since then the window size is under full control of LAF when dragging: mouseHandler set to (fi), MetalRootPaneUI does not resize the window below the minimum returned by LayoutManager. Without setting a minimum frame, you can still reduce its size programmatically.
The only way (unfortunately) to always ensure the minimum window size is to manually set it. Unfortunately, as this involves tracking the dynamic changes of this minimum and, if necessary, updating.
Snippet for playback using (un / comment the defaultDecoration and adjust the frame frame)
JFrame.setDefaultLookAndFeelDecorated(true); JPanel panel = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.BLACK); Dimension m = getMinimumSize(); // visualize the min g.drawRect(0, 0, m.width - 1, m.height -1); } }; // BEWARE: for demonstration only, NEVER do in production code panel.setMinimumSize(new Dimension(400, 400)); panel.setPreferredSize(panel.getMinimumSize()); final JXFrame frame = new JXFrame("", true); Action action = new AbstractAction("resize") { @Override public void actionPerformed(ActionEvent e) { frame.setSize(300, 300); LOG.info("succeeded? " + frame.getSize()); } }; panel.add(new JButton(action)); frame.add(panel); frame.pack(); // set minimum is required to enforce the minimum frame.setMinimumSize(frame.getMinimumSize());
Update
Looking back at the source of Window, it turns out that you can have a dynamic minimum-respect respect with automatic magic effect, overriding isMinimumSizeSet ββand returning true sub-standard:
final JXFrame frame = new JXFrame("", true) { @Override public boolean isMinimumSizeSet() { return true; } }; ...
not tested for side effects though
source share