2

because I am displaying multiple images in my java programm, each image into a new jframe. I need to identify the selected jframe in oder to make changes on the displayed image and show it in the same jframe.

So, How could I recognize the last selected jframe ?

rafaoc
  • 586
  • 7
  • 21

1 Answers1

5

I suggest you to use some other layout such as CardLayout to share same display space for multiple panel instead of using multiple JFrame.

See The Use of Multiple JFrames, Good/Bad Practice?


If you want to stick with current approach then create a global static reference of type JFrame to keep the reference of selected JFrame.

Use FocusListener to keep track of the selected JFarme

So, How could I recognize the last selected jframe ?

Keep the references of all opened JFrame and iterate all to check for JFrame#isFocused() or JFrame#isActive()

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
  • I'd prefer creating a class that implements WindowAdapter (http://docs.oracle.com/javase/7/docs/api/java/awt/event/WindowAdapter.html) and keeps track of the active frame through event callbacks over iterating over the list of frames to find the active one. – Nate Aug 18 '14 at 19:20