Timer event appears to move window



Hi Im new to Swing (and a lot other Java things to be honest) s would be
grateful for any assistance.

Im writing an app that is MDI based Ive got an JFrame MDI into which I have
a menu bar and menu items etc and a status bar (a JPanel attached to SOUTH)

One of the menu items (the only one Ive coded so far) has the following code
to create a child window (JInternalFrame) and
m
mnuNewCase.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Caseframe newCase=new Caseframe();
desktopPane.add(newCase);
}
});

which appears to open the window as expected. However whenever I grab the
window by its title bar and drag it around the MDI space (using left mouse
drag) it seems to jump back to its start position every 1 second. If I
continue to drag it it reappears where I was expecting it and the 1 second
later its back at the start position and so it goes on. If I leave go of the
left mouse button it jups back to the start and stays there.

Given its every 1 second Im assuming its something to do with the Status Bar
Ive coded on which I have a timer updating the clock on the the bottom right
of the status bar.

The StatusBar code contains the following in the initialisation code:
statusTimer=new Timer();
statusTimer.schedule(new MyStatusTask(), 0,1000);

and the following class:
private class MyStatusTask extends TimerTask {
private SimpleDateFormat formatter; // Formats the date displayed
private String today;
private String now;
private Date currentDate; // Used to get date to display

public void run() {

currentDate = new Date();
formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy",
Locale.getDefault());

formatter.applyPattern("dd/MMM/yyyy");
today = formatter.format(currentDate);
dateField.setText(today);

formatter.applyPattern("HH:mm:ss");
now = formatter.format(currentDate);
timeField.setText(now);
}
}

which to me looks ok (if a little basic etc)


any thoughts as to why the JInternalFrame jumps around ? Is it the timer
getting in the way ?


.


Quantcast