What code will facilitate making a JDialog
unmovable? I've looked at two options:
setUndecorated(true);
which works but removes all the trimmings.addComponentListener
and overriding the componentMoved()
method, which causes the JDialog
to subsequently call induceEpilepticSeizure()
upon moving. Any ideas?
My first instinct is - you can't unless you DO use setUndecorated(true)... You could manually put some trimmings there, but, well, UGH!
So if you want the native trimmings AND you want it immovable without the horrible flickering from using a component listener, I think you can't.
You could create a border manually that LOOKS like the default border...here's an example of how to do it, although I've intentionally made the border look like the ugliest thing you've seen all day. You'll need to find the right combination of BorderFactory calls to achieve what you want to do.
public static void main(String[] args) throws InterruptedException {
JDialog frame = new JDialog((Frame) null, "MC Immovable");
frame.setUndecorated(true);
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEtchedBorder(Color.GREEN, Color.RED));
panel.add(new JLabel("You can't move this"));
frame.setContentPane(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With