Results 1 to 3 of 3
  1. #1
    JavaJimme is offline Member
    Join Date
    Nov 2012
    Posts
    30
    Rep Power
    0

    Default JFrame on top of another JFrame

    Hey,

    Recently I've created a chatbox. Now I've a JFrame with emoticons in it.
    I want to add it to my chat client like this : http://i.stack.imgur.com/SmkSH.jpg in the bottom-right corner of the chatclient.
    So the emoticon JFrame always stays in the bottom-right corner of the Chatclient when you press the emociton button even if the chatclient is on a different screen position.
    emoticonFrame.setLocationRelativeTo(null); sets it to the middel of the screen when you press the button but I need the emoticon JFrame to open at the right corner of the chatclient JFrame.
    Is there a way to do that?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,969
    Rep Power
    8

    Default Re: JFrame on top of another JFrame

    Why do you need it to be a JFrame instead of a JPanel? Recommended reading: How to Use Root Panes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: JFrame on top of another JFrame

    Do the math yourself. If the width of the main frame is 500 and the width of the popup JDialog (don't use a JFrame) is 100, then you need to position your dialog at 400 relative to the main frame.

    You can get the location of the main frame by using the getLocationOnScreen(...) method.

    Then once you've calculated the width/height of the popup dialog you invoke the setLocation(...) method.

Similar Threads

  1. Click in JFrame Titlebar sets the JFrame Opaque
    By tim8w in forum AWT / Swing
    Replies: 1
    Last Post: 02-02-2013, 07:29 AM
  2. Transferring information from one JFrame to Another JFrame
    By cherylminor85 in forum AWT / Swing
    Replies: 4
    Last Post: 05-24-2012, 05:24 AM
  3. Replies: 3
    Last Post: 11-27-2011, 05:18 AM
  4. Replies: 5
    Last Post: 06-14-2010, 06:10 PM
  5. Replies: 4
    Last Post: 04-22-2009, 11:02 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
  •