Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After looking for a while, I could not find any really satisfactory solutions. I think that the resize of the dialog is something that is handled directly at the OS level and therefore you can only say that you want it totally not resizable or totally resizable.</p> <p>The code below will always prevent the dialog from being bigger, but as the user resize the dialog, the borders of the dialog still move.</p> <p>The other option, also suggested by radai, would be to prevent resize and set a Custom content pane with a mouse listener that listens for the mouse and resize accordingly. However, I think that this will not feel very native to the user (I don't think that you will be able to catch the events on the border of the dialog).</p> <pre><code>import java.awt.Frame; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import javax.swing.JDialog; import javax.swing.JRootPane; import javax.swing.SwingUtilities; public class Test { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { init(); } }); } public static void init() { final int staticHeight = 150; final JDialog dialog = new JDialog((Frame) null) { @Override protected JRootPane createRootPane() { JRootPane rp = new JRootPane() { @Override public void reshape(int x, int y, int w, int h) { super.reshape(x, y, w, staticHeight); } }; rp.setOpaque(true); return rp; } @Override public void reshape(int x, int y, int width, int height) { super.reshape(x, y, width, staticHeight); } }; dialog.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { dialog.setSize(dialog.getWidth(), staticHeight); } }); dialog.pack(); dialog.setVisible(true); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload