Results 1 to 17 of 17
  1. #1
    akcasoy is offline Member
    Join Date
    May 2008
    Posts
    8
    Rep Power
    0

    Default How to find the active Window in Swing?

    Hi all!

    I have an RCP plugin (which will be plugged into any RCP app)
    and the aim is to get the screenshot of the RCP app. So actually now what i make is, the plugin adds a new menu item to application and whenever the menu item is clicked the pluginForm opens (a form to take and manipulate the screenshots)
    But what i want is just to take the capture of the RCP app. So the plugin needs to see the current active Swing windows and get the screen size of that to take just that part of screen.
    How can i handle this?

    (btw i tried Frame.getOwnerlessWindows(), Frame.getWindows(), Frame.getFrames() methods. they dont give me the 'just rcp app window'. maybe the current running thread is just the plugin form. and it goes invisible during capture, but still there is the rcp app window running in JVM which i want to reach)

    Regards,

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    Extend the class for the window(s) and have it/them keep track of its state. Have a list of these windows that you can scan.

  3. #3
    akcasoy is offline Member
    Join Date
    May 2008
    Posts
    8
    Rep Power
    0

    Default

    Window is java.awt.Window class. how can i extend this and what for?
    if i could reach the states of the windows (especially the window of the rcp form) i could also reach the bounds and i wouldnt have problem.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    I'm sorry, I thought this was a java programming problem.
    By "active window" are you asking at the Java program level or at the OS level.
    If the OS level, you need native code.
    What is the relationship between the windows you're talking about?

  5. #5
    akcasoy is offline Member
    Join Date
    May 2008
    Posts
    8
    Rep Power
    0

    Default

    i thought the problem was pretty clear :) RCP app window.
    is of course java prog.

  6. #6
    akcasoy is offline Member
    Join Date
    May 2008
    Posts
    8
    Rep Power
    0

    Default

    The thing is this.

    I normally had 2 forms which one of those is the parent of other.
    In this RCP plugin stuation, since the plugin must work on all RCP apps, you dont have a parent form. The plugin loads itself. So how to get the parent form (RCP app form which is currently running together with the plugin in JVM)

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    What does this have to do with Swing apps?
    Sounds more like an IDE thing. How is a plugin loaded? What Java SE class does it?

  8. #8
    akcasoy is offline Member
    Join Date
    May 2008
    Posts
    8
    Rep Power
    0

    Default

    dude ok. if you dont know let somebody answer. of course this is the awt swing forum and i want to get the awt window of the current processes from jvm.

  9. #9
    jackGav is offline Member
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default

    Hi.
    Please could you try the following code:

    Java Code:
            KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
            Window window =keyboardFocusManager.getActiveWindow();

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

  11. #11
    akcasoy is offline Member
    Join Date
    May 2008
    Posts
    8
    Rep Power
    0

    Default

    Hi jackGav, thanx but it did not work. :confused:

  12. #12
    jackGav is offline Member
    Join Date
    Jun 2010
    Posts
    5
    Rep Power
    0

    Default

    Which value has the window ? null?? and
    in what part of your code are you putting the above extract?

  13. #13
    akcasoy is offline Member
    Join Date
    May 2008
    Posts
    8
    Rep Power
    0

    Default

    i got a window type of jdialog.

    as i told i have an rcp app.. and plugin also has a form..
    so when i want to take the capture, i make the plugin form invisible.. then just the main app is visible, and i put this code.. but it didnot work

  14. #14
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    this requires OS code.

    Java Code:
    JNIEXPORT jlong yourclass_blabla_getActiveWindow() {
     return (jlong) GetForegroundWindow();
    }
    or

    Java Code:
    JNIEXPORT jlong yourclass_blabla_getActiveWindow() {
     return static_cast<jlong>(GetForegroundWindow());
    }
    Last edited by JvlShz; 06-26-2010 at 04:28 PM.

  15. #15
    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 JvlShz View Post
    this requires OS code.

    Java Code:
    JNIEXPORT jlong yourclass_blabla_getActiveWindow() {
     return (jlong) GetForegroundWindow();
    }
    or

    Java Code:
    JNIEXPORT jlong yourclass_blabla_getActiveWindow() {
     return static_cast<jlong>(GetForegroundWindow());
    }
    Great, spoonfeeding incorrect code again: what is the Java part of the program supposed to do with a long value?

    kind regards,

    Jos

  16. #16
    JvlShz is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Great, spoonfeeding incorrect code again: what is the Java part of the program supposed to do with a long value?

    kind regards,

    Jos
    never thought about that, but it isn't "incorrect" in that nature.

  17. #17
    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 JvlShz View Post
    never thought about that, but it isn't "incorrect" in that nature.
    It is totally incorrect in that nature because there is no way in Java to convert the long to a reference to a Window class at all. Maybe your code snippet was technically correct but it didn't make it for an answer. You are not helping the forum, nor the OP this way.

    kind regards,

    Jos

Similar Threads

  1. How do i open JFrame in the same active window
    By Jkiller295 in forum AWT / Swing
    Replies: 35
    Last Post: 06-02-2010, 05:50 PM
  2. how to make window active and textfield focused
    By whwillisiv in forum New To Java
    Replies: 0
    Last Post: 04-28-2009, 05:06 AM
  3. Replies: 8
    Last Post: 12-01-2008, 03:07 PM
  4. Close Active Window (?)
    By dcnorman07 in forum New To Java
    Replies: 2
    Last Post: 10-03-2008, 06:55 PM
  5. Changing Active Window
    By jmHoekst in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 01:21 AM

Posting Permissions

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