It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes Event feedback loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Event feedback loop" Watch "Event feedback loop" New topic

Event feedback loop

Ian Calegory

Joined: Feb 28, 2001
Posts: 3
I'm catching a component's (in this case a JFrame) move event, and am changing the component's location, which fires off another move event, and so on. Does someone know how to suppress the subsequent move events? Thanks!
Bryan Fagan

Joined: Feb 26, 2001
Posts: 17
Hi Ian:
I believe what you are looking for is the SwingUtilities.invokeLater method. The method waits for all events to occur and then executes your code. This means your componentMoved method is only executed once.
See code below.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class Test extends JFrame {
public Test() {
addComponentListener(new ComponentListen());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
public static void main(String[] args) {
Test tst = new Test();

class ComponentListen implements ComponentListener {
public void componentHidden(ComponentEvent ce) {

public void componentMoved(ComponentEvent me) {
SwingUtilities.invokeLater(new moveFrame(me));
// moveFrame inner class to move the frame.
class moveFrame implements Runnable {
ComponentEvent mo;
moveFrame(ComponentEvent mo) { = mo;
public void run() {
Component com = (Component)mo.getComponent();
public void componentResized(ComponentEvent cce) {
public void componentShown(ComponentEvent cs) {
I agree. Here's the link:
subject: Event feedback loop
It's not a secret anymore!