Results 1 to 15 of 15
  1. #1
    divs1210 is offline Member
    Join Date
    Apr 2011
    Posts
    16
    Rep Power
    0

    Question Disable repositioning of JFrame

    Hey! I am developing an application that i don't want the user to be able to drag across the screen.

    any possible way i could do that?

  2. #2
    divs1210 is offline Member
    Join Date
    Apr 2011
    Posts
    16
    Rep Power
    0

    Default

    also, how can i change the color of the frame?

    setBackground(Color.WHITE); seems to have no effect.

    im sorry if this has already been asked. just give me a link to that page.

  3. #3
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    try this...
    Java Code:
    FrameName.setResizable(false);
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm not sure how to disable dragging of the JFrame, but to set the background to white, you'll need to get the JFrame's contentPane (via getContentPane()) and set its background via setBackground().

  5. #5
    divs1210 is offline Member
    Join Date
    Apr 2011
    Posts
    16
    Rep Power
    0

    Default

    @ujjal ive already set resizing to false.
    @Fubarable oh, yes. what was i thinking? thanks!

    pls let me know if you find out about the resizing thing.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    i don't want the user to be able to drag across the screen.
    I have to ask, why? If I found this behavior in any application, I would immediately uninstall it.

    Anyhow. One way is to use a JWindow instead of a JFrame, as it doesn't have a title bar and so can't be dragged. Another way is to setUndcorated(true) on a JFrame, which removes its title bar.

    In either case, you'll need to provide a means for the user to close the application. Or do you want to prevent that too?

    db

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by divs1210 View Post
    @ujjal ive already set resizing to false.
    @Fubarable oh, yes. what was i thinking? thanks!

    pls let me know if you find out about the resizing thing.
    You can't 'forbid' a JFrame from being moved, it's part of the system GUI; the best you can do is add a ComponentListener to the JFrame and put it back at its original place when it's being moved. I think the visual effects are quite funny.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Good morning (or whatever it is for you!), Darryl and Jos.

    /Pete

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Fubarable View Post
    Good morning (or whatever it is for you!), Darryl and Jos.

    /Pete
    It's 3:30pm overhere already; it's sunny and I'm sitting in my back garden (I love that!). Now that you've mentioned it: where's my Grolsch?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    Quote Originally Posted by divs1210 View Post
    Hey! I am developing an application that i don't want the user to be able to drag across the screen.

    any possible way i could do that?
    Oh Sorry,
    I thought that you wanna disable sizing.You wanna make stable your window? That's not done.I dont know how to do this,just you can't prevent an user to do this.
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  11. #11
    divs1210 is offline Member
    Join Date
    Apr 2011
    Posts
    16
    Rep Power
    0

    Default

    @Darryl thanks for the reply.... and the sarcasm. Got what i wanted, though!
    @JosAH thanks for your reply. Already tried doing that. looks odd. :D

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    Good morning (or whatever it is for you!), Darryl and Jos.

    /Pete
    Night here, now (evening when you posted that).

    India just won, crackers being set off all around so my dog has squeezed between my feet and the computer table.

    db

  13. #13
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Quote Originally Posted by divs1210 View Post
    @Darryl thanks for the reply.... and the sarcasm. Got what i wanted, though!
    @JosAH thanks for your reply. Already tried doing that. looks odd. :D
    I still feel you ought to rethink the requirement. It's abnormal.

    db

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Darryl.Burke View Post
    I still feel you ought to rethink the requirement. It's abnormal.
    Seconded. Perhaps you have a good reason for wanting to do this, but you may wish to justify this reason with us.

  15. #15
    divs1210 is offline Member
    Join Date
    Apr 2011
    Posts
    16
    Rep Power
    0

    Default

    well, i'll tell u my idea in brief:


    i actually wanted a window with a transparent frame. I thought ill do that the way picassa does it, u know, when it's in full-screen mode, it just captures a pic of the desktop, and pastes it as a background.

    but when u minimise it, it just shows a grey background, because if u move the window, the background should change.

    my application runs ONLY in windowed mode, so the above problem is a serious one. i read somewhere that the best option to tackle this would be to capture a new picture everytime the window is moved. but i felt too lazy, and though there *might* be a way to stop repositioning it, killing the need for everything else in the first place.

    ....but i get u. its NOT a good idea. so i'll not do it.

Similar Threads

  1. Disable Maximize button in JFrame?
    By Manish87 in forum AWT / Swing
    Replies: 0
    Last Post: 02-01-2011, 04:39 PM
  2. Replies: 6
    Last Post: 11-22-2010, 12:55 PM
  3. Objects repositioning automatically
    By ashish9590 in forum NetBeans
    Replies: 5
    Last Post: 06-30-2010, 01:10 PM
  4. repositioning
    By ashish9590 in forum NetBeans
    Replies: 2
    Last Post: 02-14-2010, 07:42 AM
  5. Repositioning An unwanted JInternalFrame
    By marco.c84 in forum AWT / Swing
    Replies: 8
    Last Post: 03-18-2009, 10:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •