-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
7u40
-
linux_ubuntu
FULL PRODUCT VERSION :
java version " 1.7.0_40-ea "
Java(TM) SE Runtime Environment (build 1.7.0_40-ea-b38)
Java HotSpot(TM) Server VM (build 24.0-b55, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Ubuntu 12.04, 3.2.0-52-generic-pae
A DESCRIPTION OF THE PROBLEM :
JFrame's getBounds() reports wrong bounds - not always, but often.
This makes it " impossible " to use this information to restore frame size and postion at next program startup.
REGRESSION. Last worked in version 6u45
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) create a JFrame
2) set valid bounds
3) on windowClosing query bounds
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Without moving/resizing the window, getBounds() should report the bounds set before
ACTUAL -
Wrong result - example output from testprogram (bounds always set to 100,100,800,600):
bounds set to java.awt.Rectangle[x=100,y=100,width=800,height=600]
bounds on close java.awt.Rectangle[x=101,y=128,width=800,height=600]
bounds set to java.awt.Rectangle[x=100,y=100,width=792,height=599]
bounds on close java.awt.Rectangle[x=100,y=100,width=800,height=600]
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.awt.EventQueue;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.Timer;
import javax.swing.WindowConstants;
public class ErrJFrame
extends JFrame {
final Rectangle rStart;
public ErrJFrame() {
super( " test " );
rStart = new Rectangle(100, 100, 800, 600);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
final Rectangle rb = getBounds();
System.out.println( " bounds on close " + rb);
}
});
setPreferredSize(rStart.getSize());
setBounds();
// --- " auto-close "
final Timer t = new Timer(500, new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final WindowEvent wev =
new WindowEvent(ErrJFrame.this, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
}
});
t.setRepeats(false);
t.start();
}
void setBounds() {
setBounds(rStart);
setVisible(true);
System.out.println( " bounds set to " + getBounds());
}
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
@SuppressWarnings( " unused " )
@Override
public void run() {
new ErrJFrame();
}
});
}
}
---------- END SOURCE ----------
java version " 1.7.0_40-ea "
Java(TM) SE Runtime Environment (build 1.7.0_40-ea-b38)
Java HotSpot(TM) Server VM (build 24.0-b55, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Ubuntu 12.04, 3.2.0-52-generic-pae
A DESCRIPTION OF THE PROBLEM :
JFrame's getBounds() reports wrong bounds - not always, but often.
This makes it " impossible " to use this information to restore frame size and postion at next program startup.
REGRESSION. Last worked in version 6u45
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) create a JFrame
2) set valid bounds
3) on windowClosing query bounds
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Without moving/resizing the window, getBounds() should report the bounds set before
ACTUAL -
Wrong result - example output from testprogram (bounds always set to 100,100,800,600):
bounds set to java.awt.Rectangle[x=100,y=100,width=800,height=600]
bounds on close java.awt.Rectangle[x=101,y=128,width=800,height=600]
bounds set to java.awt.Rectangle[x=100,y=100,width=792,height=599]
bounds on close java.awt.Rectangle[x=100,y=100,width=800,height=600]
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.awt.EventQueue;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.Timer;
import javax.swing.WindowConstants;
public class ErrJFrame
extends JFrame {
final Rectangle rStart;
public ErrJFrame() {
super( " test " );
rStart = new Rectangle(100, 100, 800, 600);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
final Rectangle rb = getBounds();
System.out.println( " bounds on close " + rb);
}
});
setPreferredSize(rStart.getSize());
setBounds();
// --- " auto-close "
final Timer t = new Timer(500, new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final WindowEvent wev =
new WindowEvent(ErrJFrame.this, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
}
});
t.setRepeats(false);
t.start();
}
void setBounds() {
setBounds(rStart);
setVisible(true);
System.out.println( " bounds set to " + getBounds());
}
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
@SuppressWarnings( " unused " )
@Override
public void run() {
new ErrJFrame();
}
});
}
}
---------- END SOURCE ----------