0

I currently have 2 frames in my application. The first one is the main frame and has a toolbar that has accelerators (CTRL-Z, CTRL-Y, etc..) set on it.

Currently when the second frame is focused none of the accelerators will work. Is there a way i can pass the keyboard events to the first frame from the second?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Riverchimp
  • 404
  • 5
  • 14
  • 3
    Why would you want to? The functionality that they provide are probably contextual to the frame in which they are defined – MadProgrammer Jul 19 '14 at 02:08
  • 3
    First of all you should NOT be using 2 frames, the second should be a JDialog. `Currently when the second frame is focused none of the accelerators will work.` that is a good thing. You should NOT be trying to invoke an Action from one Window of another Window. The reason you have two Windows is to keep the functionality separate. Show me another application, like IE or Word that allow one Window to invoke toolbar Action of another Window. – camickr Jul 19 '14 at 02:08
  • 4
    Also, have a look at [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice) – MadProgrammer Jul 19 '14 at 02:08
  • This [post](http://stackoverflow.com/a/14118916/1057230) by @mKorbel, might can help you, to generate fake events for some another `component` – nIcE cOw Jul 19 '14 at 03:37

1 Answers1

0

Please consider all the other guys' warnings.. but you could do it by implementing an Observer pattern.

First frame -> Implements Observer. Second frame is an Observable (contains a list of observers)

When you create the second frame, "register" the first frame (add to the second frame's list of observers). When second frame receives inputs, also tell its list of Observers that you received an input. You can even have more than 2 frames and they'll all receive inputs. (oh my god, why? :P)

Breno Inojosa
  • 602
  • 1
  • 10
  • 20