

// When running the following app on Windows the frames are (as expected) the 
// same size, but when run on Ubuntu Linux roughly 70% of the time the 2 frames 
// have different heights. 
// 
// On Ubuntu, when the frames are different heights the 1st frame made visible 
// is always the taller of the two frames. Thus in the example as written, if
// the frames are are not the same size then f1 will always be taller than f2, 
// but if the example is changed to make f2 visible before f1, then f2 will be 
// taller than f1.
//
// The inconsistent behavior hinted at a possible race condition when rendering 
// the two frames, so the test was modified to add a timer to delay the rendering
// of the 2nd frame, as shown below in test2. However, if anything, this seemed 
// to make it even less likely that the two frames would be the same size.
//
// Ubuntu version:  14.04 LTS
// Java version:    1.8.0_31
//
/***
Linux art-Inspiron-N5010 3.13.0-32-generic #57-Ubuntu SMP 
Tue Jul 15 03:51:12 UTC 2014 i686 i686 i686 GNU/Linux

java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) Server VM (build 25.31-b07, mixed mode)
***/


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.Timer;

public class JFrameSizingErrorExample implements Runnable {
	public static void main(String[] args) {
		java.awt.EventQueue.invokeLater(new JFrameSizingErrorExample());
	}

	@Override public void run() {
		final JFrame f1 = new MyFrame(1, 250, 100);
		final JFrame f2 = new MyFrame(2, 600, 100);
		f1.setVisible(true);
		f2.setVisible(true);
	}
	
	class MyFrame extends JFrame {
		public MyFrame(int frameNum, int x, int y) {
			setTitle("Frame-" + frameNum);
			setLocation(x, y);
			setSize(300, 200);
			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		}
	}
	
	void test2()
	{
		final JFrame f1 = new MyFrame(1, 32, 32);
		final JFrame f2 = new MyFrame(2, 600, 32);
		f1.setVisible(true);
		
        Timer timer = new Timer(1000 ,new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
            	f2.setVisible(true);
            }
        });
        timer.setRepeats(false);
        timer.start();			
	}
}
