java - How to propogate Swing events from a inner component to a container? -
I created a component based on a JPNL that contains a textfield and a checkbox because I use it as a component And keep it in the other panels, so I want to be able to set a key event for the panel. Obiouvsly does not work as the keyPressed incidents fire for this internal text field. Is this a way to broadcast them to JPNL because it was receiving them instead of textfiles? I tried with handleEvent, but it also does not compile
make this question clear. I have made this big element a textfield. Now I have to use this element in another and I want to set the other as a listener. So among those there is JPanel that's the problem.
You can use javax.swing.event.EventListenerList in jpeanfield with jettaxfile, and add an addKeyListener Create public method.
Import javax.swing.event.EventListenerList; Public Static Class TestPanel implements JPanel KeyListener {Private JTextField Text; Private Event List Author List Listener List = New Event List Author (); TestPanel () {text = New JTextField (); Text.addKeyListener (this); } Public Zero Key Pressed (KEY EVE) {// does not prepare a new array used for the reasons for the display [object] [listeners = listenerList.getListenerList (); // The array of listeners is the class [i] class, the event listener for the audience [i + 1] (int i = listeners. Closing - 2; i; i> = 0; i - = 2) {if (listeners [ I] = = KeyListener.class {{KeyListener} listeners [i + 1]) keypressed (e); }}} Public Zero addKeyListener (KeyListener) {listenerList.add (KeyListener.class, l); } Public Zero Key Relayed (KeyEvent E) {// ID as keyPressed} Public void keyTyped (KeyEvent e) {// idem as keyPressed}}
Comments
Post a Comment