How to stop a jframe from being moved

Discussion in 'Java' started by clusardi2k, Aug 31, 2012.

  1. clusardi2k

    clusardi2k Guest

    How can I prevent/stop a jframe from being moved on the monitor.

    Thank you,
    clusardi2k, Aug 31, 2012
    1. Advertisements

  2. clusardi2k

    Eric Sosman Guest

    What a horrible idea!

    There are lots of ways. A few of the more sensible:

    - Turn off the monitor.

    - Uninstall the drivers for all user interaction devices.

    - Turn off the computer.

    - Electrocute the user.

    A few of the less sensible:

    - Use a javax.swing.Timer to forcibly reposition the JFrame
    every delta-T milliseconds, thus negating the user's attempt
    to move it. (For extra credit, play a sound clip of a
    maniacal laugh.)

    - See if there's a way to listen for window movement events,
    and forcibly reposition when/if they occur. Doesn't look
    like WindowListener will do this, but maybe you can hack
    up some weird combination of WindowFocusListener and
    MouseAdapter to get the notification you need, possibly
    using the JFrame's glass pane.

    - Maybe if you suppress the window decorations there won't
    be a "move window" handle.

    - Maybe using full-screen exclusive mode would help with some
    of the approaches mentioned above.
    Two words you're unlikely to hear from your users.

    The single most important reason to have a windowing system in
    the first place is to allow multiple applications to share display
    space and input devices. When you say "*My* application always
    owns this chunk of screen real estate," you are also saying "*My*
    application's need for that bit of screen is greater than that
    of any other application, *even those I've never imagined.*" The
    ancient Greeks called this attitude "ὕβÏις," and displaying ὕβÏις
    was an excellent way to get yourself punished by the dwellers
    on Olympus ...
    Eric Sosman, Aug 31, 2012
    1. Advertisements

  3. clusardi2k

    clusardi2k Guest

    Using the following event produces a jerky effect. Do you have something better!

    private void formComponentMoved(java.awt.event.ComponentEvent evt)


    clusardi2k, Aug 31, 2012
  4. clusardi2k

    clusardi2k Guest

    I also get the below exception trace when the project starts:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Toy_Package.Toy_Obj.formComponentMoved(
    at Toy_Package.Toy_Obj.access$000(
    at Toy_Package.Toy_Obj$2.componentMoved(
    at java.awt.AWTEventMulticaster.componentMoved(


    clusardi2k, Aug 31, 2012
  5. How about the legal way?
    OP should add a subparagraph 12.4.2 to their software's EULA,
    that simply forbids the licencee("user") to move certain/all
    of the application's windows.
    Andreas Leitgeb, Aug 31, 2012
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.