Java Code Examples for javax.swing.JFrame.setLocation()

The following are Jave code examples for showing how to use setLocation() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ALTTPMenuPractice   File: MenuPractice.java   View Source Code Vote up 7 votes
/**
 * Warning with instructions for failed library loading
 */
public static void showWarning() {
	// try to set LaF
	try {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	} catch (Exception e2) {
		// do nothing
	} //end System
	JFrame x = new JFrame();
	x.setLayout(new BorderLayout());
	x.setTitle("Libraries missing");
	x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	x.add(new JLabel(
			String.join("",
					new String[] {
							"<html>",
							"<div style=\"padding: 13px; font-size: 10px;\">",
							"Your /lib directory not contain all necessary libraries to run JInput.",
							"<br /><br />",
							"To remedy this, download the latest release of MenuSimulator from",
							"<br />",
							"https://github.com/fatmanspanda/ALTTPMenuPractice/releases",
							"<br /><br />",
							"The application will halt when you close this window.",
							"</div>",
							"</html>"
			})),
			BorderLayout.NORTH);
	x.setMinimumSize(new Dimension(500,300));
	x.setLocation(200, 200);
	x.setVisible(true);
}
 
Example 2
Project: incubator-netbeans   File: PropertyMarkingTest.java   View Source Code Vote up 6 votes
protected void setUp() throws Exception {
    if (setup) return;
    PropUtils.forceRadioButtons=false;
    
    try {
        
        tp = new TProperty("oh", true);
        tp1 = new TProperty2("the", true);
        tp2 = new TProperty2("pretty", true);
        tp3 = new TProperty2("pictures",true);
        tp4 = new TProperty3("I can create",true);
        postSetAction = new PostSetAction();
        
        tn = new TNode();
        
        final PropertySheet ps = new PropertySheet();
        
        //ensure no stored value in preferences:
        ps.setCurrentNode(tn);
        sleep();
        ps.setSortingMode(PropertySheet.UNSORTED);
        
        jf = new JFrame();
        jf.getContentPane().add(ps);
        jf.setLocation(20,20);
        jf.setSize(300, 400);
        new WaitWindow(jf);
        tb = ps.table;
        
        ps.setSortingMode(ps.SORTED_BY_NAMES);
        jf.repaint();
        
        
    } catch (Exception e) {
        e.printStackTrace();
        fail("FAILED - Exception thrown "+e.getClass().toString());
    } finally {
        setup = true;
    }
}
 
Example 3
Project: SER316-Ingolstadt   File: App.java   View Source Code Vote up 6 votes
/**
 * Method showSplash.
 */
private void showSplash() {
	splash = new JFrame();
	ImageIcon spl =
		new ImageIcon(App.class.getResource("resources/splash.png"));
	JLabel l = new JLabel();
	l.setSize(400, 300);
	l.setIcon(spl);
	splash.getContentPane().add(l);
	splash.setSize(400, 300);
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	splash.setLocation(
		(screenSize.width - 400) / 2,
		(screenSize.height - 300) / 2);
	splash.setUndecorated(true);
	splash.setVisible(true);
}
 
Example 4
Project: Reinickendorf_SER316   File: App.java   View Source Code Vote up 6 votes
/**
 * Method showSplash.
 */
private void showSplash() {
	splash = new JFrame();
	ImageIcon spl =
		new ImageIcon(App.class.getResource("resources/splash.png"));
	JLabel l = new JLabel();
	l.setSize(400, 300);
	l.setIcon(spl);
	splash.getContentPane().add(l);
	splash.setSize(400, 300);
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	splash.setLocation(
		(screenSize.width - 400) / 2,
		(screenSize.height - 300) / 2);
	splash.setUndecorated(true);
	splash.setVisible(true);
}
 
Example 5
Project: SER316-Aachen   File: App.java   View Source Code Vote up 6 votes
/**
 * Method showSplash.
 */
private void showSplash() {
	splash = new JFrame();
	ImageIcon spl =
		new ImageIcon(App.class.getResource("resources/splash.png"));
	JLabel l = new JLabel();
	l.setSize(400, 300);
	l.setIcon(spl);
	splash.getContentPane().add(l);
	splash.setSize(400, 300);
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	splash.setLocation(
		(screenSize.width - 400) / 2,
		(screenSize.height - 300) / 2);
	splash.setUndecorated(true);
	splash.setVisible(true);
}
 
Example 6
Project: openjdk-jdk10   File: CompositionArea.java   View Source Code Vote up 5 votes
CompositionArea() {
    // create composition window with localized title
    String windowTitle = Toolkit.getProperty("AWT.CompositionWindowTitle", "Input Window");
    compositionWindow =
        (JFrame)InputMethodContext.createInputMethodWindow(windowTitle, null, true);

    setOpaque(true);
    setBorder(LineBorder.createGrayLineBorder());
    setForeground(Color.black);
    setBackground(Color.white);

    // if we get the focus, we still want to let the client's
    // input context handle the event
    enableInputMethods(true);
    enableEvents(AWTEvent.KEY_EVENT_MASK);

    compositionWindow.getContentPane().add(this);
    compositionWindow.addWindowListener(new FrameWindowAdapter());
    addInputMethodListener(this);
    compositionWindow.enableInputMethods(false);
    compositionWindow.pack();
    Dimension windowSize = compositionWindow.getSize();
    Dimension screenSize = (getToolkit()).getScreenSize();
    compositionWindow.setLocation(screenSize.width - windowSize.width-20,
                                screenSize.height - windowSize.height-100);
    compositionWindow.setVisible(false);
}
 
Example 7
Project: OpenJSharp   File: CompositionArea.java   View Source Code Vote up 5 votes
CompositionArea() {
    // create composition window with localized title
    String windowTitle = Toolkit.getProperty("AWT.CompositionWindowTitle", "Input Window");
    compositionWindow =
        (JFrame)InputMethodContext.createInputMethodWindow(windowTitle, null, true);

    setOpaque(true);
    setBorder(LineBorder.createGrayLineBorder());
    setForeground(Color.black);
    setBackground(Color.white);

    // if we get the focus, we still want to let the client's
    // input context handle the event
    enableInputMethods(true);
    enableEvents(AWTEvent.KEY_EVENT_MASK);

    compositionWindow.getContentPane().add(this);
    compositionWindow.addWindowListener(new FrameWindowAdapter());
    addInputMethodListener(this);
    compositionWindow.enableInputMethods(false);
    compositionWindow.pack();
    Dimension windowSize = compositionWindow.getSize();
    Dimension screenSize = (getToolkit()).getScreenSize();
    compositionWindow.setLocation(screenSize.width - windowSize.width-20,
                                screenSize.height - windowSize.height-100);
    compositionWindow.setVisible(false);
}
 
Example 8
Project: Community_Tieba-Data-Analyzer   File: Test.java   View Source Code Vote up 5 votes
private static void onGUI(){
	frame = new JFrame("Encrypter");
	en = new JButton("Encrypt");
	de = new JButton("Decrypt");
	panel = new JPanel();
	panel2 = new JPanel();
	panel3 = new JPanel();
	input = new JTextField("input file this is");
	output = new JTextField(10);
	code  = new JTextField(5);
	codeIn = new JTextField("Enter the Registration ID Raw");
	trans = new JButton("Get the Real Registration ID");
	frame.getContentPane().add(panel, BorderLayout.NORTH);
	frame.getContentPane().add(panel2, BorderLayout.CENTER);
	frame.getContentPane().add(panel3, BorderLayout.SOUTH);
	panel.add(input);
	panel.add(output);
	panel.add(code);
	panel2.add(en);
	panel2.add(de);
	panel3.setLayout(new GridLayout(2,1));
	panel3.add(codeIn);
	panel3.add(trans);
	trans.addActionListener(event -> getRealID(codeIn.getText()));
	en.addActionListener(event -> encrypt(input.getText(),output.getText(),Integer.parseInt(code.getText())));
	de.addActionListener(event -> decrypt(input.getText(),output.getText(),Integer.parseInt(code.getText())));
	frame.setLocation(1366/3, 768/3);
	frame.setDefaultCloseOperation(3);
	frame.setSize(500, 300);
	frame.setVisible(true);
}
 
Example 9
Project: EMC-Installer   File: Progressbar.java   View Source Code Vote up 5 votes
public Progressbar(String title, int max) {
	pbar = new JProgressBar();
	pbar.setMinimum(0);
	pbar.setMaximum(max);
	pbar.setPreferredSize(new Dimension(500, 20));
	add(pbar);
	JFrame frame = new JFrame(title);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setContentPane(this);
	frame.setSize(new Dimension(500, 65));
	frame.setVisible(true);
	Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
	frame.setLocation(dim.width / 2 - this.getSize().width / 2, dim.height / 2 - this.getSize().height / 2);
}
 
Example 10
Project: Community_Tieba-Data-Analyzer   File: Util.java   View Source Code Vote up 5 votes
public static void errMessage(String s){
	JFrame frame = new JFrame("Error Message");
	JLabel label = new JLabel(s);
	JPanel panel = new JPanel();
	frame.getContentPane().add(panel);
	panel.add(label);
	frame.setVisible(true);
	frame.setSize(s.length() * 7, 100);
	frame.setLocation(Config.getIns().getWindowXLocation(), Config.getIns().getWindowYLocation());
	frame.setResizable(true);
	frame.setDefaultCloseOperation(3);
}
 
Example 11
Project: FE8CM   File: FE8CM.java   View Source Code Vote up 5 votes
public static void main(String[] args)
{ 
   JFrame frame = new JFrame("GBA Fire Emblem Conversation Maker");
   frame.setResizable(false);
   frame.setSize(width, height);
   frame.setLocation(0, 0);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setContentPane(new MainPanel());
   frame.setVisible(true);
}
 
Example 12
Project: jaer   File: CollapsablePanel.java   View Source Code Vote up 5 votes
public static void main(String[] args) {  
	  
    CollapsablePanel cp = new CollapsablePanel("test", buildPanel());  
  
    JFrame f = new JFrame();  
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
    f.getContentPane().add(new JScrollPane(cp));  
    f.setSize(360, 500);  
    f.setLocation(200, 100);  
    f.setVisible(true);  
}
 
Example 13
Project: jdk8u-jdk   File: bug8071705.java   View Source Code Vote up 5 votes
private static Rectangle setLocation(JFrame frame, GraphicsDevice device) {
    GraphicsConfiguration conf = device.getDefaultConfiguration();
    Rectangle bounds = conf.getBounds();

    // put just below half screen
    int x = bounds.x + bounds.width/2;
    int y = bounds.y + bounds.height/2;
    frame.setLocation(x, y);

    return bounds;
}
 
Example 14
Project: SpotSpotter   File: TextField.java   View Source Code Vote up 5 votes
public static void JTextFieldDemo1() {

		jf = new JFrame("TextField����");

		final Container contentPane = jf.getContentPane();
		contentPane.setLayout(new BorderLayout());

		jp = new JPanel();

		jtf1 = new JTextField();
		jtf2 = new JTextField(10);
		jtf3 = new JTextField("ָ���ı�����");
		jtf4 = new JTextField("ָ������+ָ������(ֻ��״̬)", 30);

		jtf3.setEnabled(false); // true���Ա༭
		jtf4.setFont(new Font("����", Font.BOLD | Font.ITALIC, 16)); // ���壬�Ƿ�Ӵ֡�б�壬�ֺ�
		// �����ı���ˮƽ���뷽ʽ
		jtf4.setHorizontalAlignment(SwingConstants.CENTER);

		jp.add(jtf1);
		jp.add(jtf2);
		jp.add(jtf3);
		jp.add(jtf4);

		contentPane.add(jp);

		jf.pack();
		jf.setLocation(400, 200);
		jf.setVisible(true);
		jf.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}
 
Example 15
Project: incubator-netbeans   File: IndexedPropertyTest.java   View Source Code Vote up 4 votes
protected void setUp() throws Exception {
    // Create new TEditor
    te = new TEditor();
    // Create new TNode
    tn = new TNode();
    
    //Replacing NodeOp w/ JFrame to eliminate depending on full IDE init
    //and long delay while waiting for property sheet thus requested to
    //initialize
    final JFrame jf = new JFrame();
    ps = new PropertySheet();
    jf.getContentPane().setLayout(new BorderLayout());
    jf.getContentPane().add(ps, BorderLayout.CENTER);
    jf.setLocation(30,30);
    jf.setSize(500,500);
    
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            ps.setNodes(new Node[] {tn});
            //ps.setCurrentNode(tn);
            jf.show();
        }
    });
    
    jf.show();
    new ExtTestCase.WaitWindow(jf);
    
    try {
        // Wait for the initialization
        for (int i = 0; i < 10; i++) {
            final String asText = te.getAsText();
            if (asText == null || asText.equals("null")) {
                //System.out.println("null");
                Thread.sleep(1000);
            } else break;
        }
        ensurePainted(ps);
        
    } catch (Exception e) {
        fail("FAILED - Exception thrown "+e.getClass().toString());
    }
}
 
Example 16
Project: incubator-netbeans   File: NodeDeletionTest.java   View Source Code Vote up 4 votes
protected void setUp() throws Exception {
    // Create new TEditor
    te = new TEditor();
    // Create new TNode
    tn = new TNode();
    
    //Replacing NodeOp w/ JFrame to eliminate depending on full IDE init
    //and long delay while waiting for property sheet thus requested to
    //initialize
    final JFrame jf = new JFrame();
    ps = new PropertySheet();
    jf.getContentPane().setLayout(new BorderLayout());
    jf.getContentPane().add(ps, BorderLayout.CENTER);
    jf.setLocation(30,30);
    jf.setSize(500,500);
    final Node[] nodes = new Node[]{tn};
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            ps.setNodes(nodes);
            //ps.setCurrentNode(tn);
            jf.show();
        }
    });
    
    jf.show();
    new ExtTestCase.WaitWindow(jf);
    
    try {
        // Wait for the initialization
        for (int i = 0; i < 10; i++) {
            final String asText = te.getAsText();
            if (asText == null || asText.equals("null")) {
                //System.out.println("null");
                Thread.sleep(1000);
            } else break;
        }
        ensurePainted(ps);
        
    } catch (Exception e) {
        fail("FAILED - Exception thrown "+e.getClass().toString());
    }
}
 
Example 17
Project: incubator-netbeans   File: EditableDisplayerTest.java   View Source Code Vote up 4 votes
protected void setUp() throws Exception {
    
    //            UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
    //            UIManager.setLookAndFeel(new com.sun.java.swing.plaf.gtk.GTKLookAndFeel());
    PropUtils.forceRadioButtons=false;
    try {
        //            if (setup) return;
        basicProp= new BasicProperty("basicProp", true);
        System.err.println("Created basicProp at " + System.currentTimeMillis() + " - " + basicProp);
        
        tags1 = new TagsProperty("tags1", true, new String[] {"What","is","the","meaning","of","life"});
        tags2 = new TagsProperty("tags2", true, new String[] {"Austrolopithecines","automatically","engender","every","one"});
        tags3 = new TagsProperty("tags3", true, new String[] {"Behold","the","power","of","cheese"});
        booleanProp = new BooleanProperty("booleanProp", true);
        customProp = new CustomProperty("CustomProp", true);
        customProp2 = new CustomProperty("CustomProp2", true);
        ExceptionProperty exProp = new ExceptionProperty("Exception prop", true);
        NumProperty numProp = new NumProperty("Int prop", true);
        EditableNumProperty edProp = new EditableNumProperty("Editable", true);
        stringProp = new StringProperty("stringProp",true);
        
        // Create new BasicEditor
        te = new BasicEditor();
        // Create new TNode
        tn = new TNode();
        
        System.err.println("Crating frame");
        jf = new JFrame();
        jf.getContentPane().setLayout(new BorderLayout());
        jp = new JPanel();
        jp.setLayout(new FlowLayout());
        jf.getContentPane().add(jp, BorderLayout.CENTER);
        jf.setLocation(20,20);
        jf.setSize(600, 200);
        
        synchronized (jp.getTreeLock()) {
            System.err.println("BasicProp = " + basicProp);
            
            basicRen = new EditablePropertyDisplayer(basicProp);
            tagsRen1 = new EditablePropertyDisplayer(tags1);
            tagsRen2 = new EditablePropertyDisplayer(tags2);
            tagsRen3 = new EditablePropertyDisplayer(tags3);
            boolRen = new EditablePropertyDisplayer(booleanProp);
            custRen = new EditablePropertyDisplayer(customProp);
            custRen2 = new EditablePropertyDisplayer(customProp2);
            exRen = new EditablePropertyDisplayer(exProp);
            numRen = new EditablePropertyDisplayer(numProp);
            edRen = new EditablePropertyDisplayer(edProp);
            stringRen = new EditablePropertyDisplayer(stringProp);
            
            tagsRen2.setRadioButtonMax(10);
            
            jp.add(basicRen);
            jp.add(tagsRen1);
            jp.add(tagsRen2);
            jp.add(tagsRen3);
            jp.add(boolRen);
            jp.add(custRen);
            jp.add(custRen2);
            jp.add(numRen);
            jp.add(edRen);
            jp.add(stringRen);
        }
        
        System.err.println("Waiting for window");
        new WaitWindow(jf);  //block until window open
        System.err.println("Window shown");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        setup = true;
    }
}
 
Example 18
Project: Tarski   File: SimpleGUI.java   View Source Code Vote up 4 votes
/** The constructor; this method will be called by the AWT event thread, using the "invokeLater" method. */
private SimpleGUI (final String[] args) {

    // Register an exception handler for uncaught exceptions
    MailBug.setup();

    // Enable better look-and-feel
    if (Util.onMac() || Util.onWindows()) {
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Alloy Analyzer "+Version.version());
        System.setProperty("com.apple.mrj.application.growbox.intrudes","true");
        System.setProperty("com.apple.mrj.application.live-resize","true");
        System.setProperty("com.apple.macos.useScreenMenuBar","true");
        System.setProperty("apple.laf.useScreenMenuBar","true");
        try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Throwable e) { }
    }

    // Figure out the desired x, y, width, and height
    int screenWidth=OurUtil.getScreenWidth(), screenHeight=OurUtil.getScreenHeight();
    int width=AnalyzerWidth.get();
    if (width<=0) width=screenWidth/10*8; else if (width<100) width=100;
    if (width>screenWidth) width=screenWidth;
    int height=AnalyzerHeight.get();
    if (height<=0) height=screenHeight/10*8; else if (height<100) height=100;
    if (height>screenHeight) height=screenHeight;
    int x=AnalyzerX.get(); if (x<0) x=screenWidth/10; if (x>screenWidth-100) x=screenWidth-100;
    int y=AnalyzerY.get(); if (y<0) y=screenHeight/10; if (y>screenHeight-100) y=screenHeight-100;

    // Put up a slash screen
    final JFrame frame = new JFrame("Alloy Analyzer");
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.pack();
    if (!Util.onMac() && !Util.onWindows()) {
       String gravity = System.getenv("_JAVA_AWT_WM_STATIC_GRAVITY");
       if (gravity==null || gravity.length()==0) {
          // many Window managers do not respect ICCCM2; this should help avoid the Title Bar being shifted "off screen"
          if (x<30) { if (x<0) x=0; width=width-(30-x);   x=30; }
          if (y<30) { if (y<0) y=0; height=height-(30-y); y=30; }
       }
       if (width<100) width=100;
       if (height<100) height=100;
    }
    frame.setSize(width,height);
    frame.setLocation(x,y);
    frame.setVisible(true);
    frame.setTitle("Alloy Analyzer "+Version.version()+" loading... please wait...");
    final int windowWidth = width;
    // We intentionally call setVisible(true) first before settings the "please wait" title,
    // since we want the minimized window title on Linux/FreeBSD to just say Alloy Analyzer

    // Test the allowed memory sizes
    final WorkerEngine.WorkerCallback c = new WorkerEngine.WorkerCallback() {
        private final List<Integer> allowed = new ArrayList<Integer>();
        private final List<Integer> toTry = new ArrayList<Integer>(Arrays.asList(256,512,768,1024,1536,2048,2560,3072,3584,4096));
        private int mem;
        public synchronized void callback(Object msg) {
            if (toTry.size()==0) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() { SimpleGUI.this.frame=frame; SimpleGUI.this.finishInit(args, allowed, windowWidth); }
                });
                return;
            }
            try { mem=toTry.remove(0); WorkerEngine.stop(); WorkerEngine.run(dummyTask, mem, 128, "", "", this); return; } catch(IOException ex) { fail(); }
        }
        public synchronized void done() {
            //System.out.println("Alloy4 can use "+mem+"M"); System.out.flush();
            allowed.add(mem);
            callback(null);
        }
        public synchronized void fail() {
            //System.out.println("Alloy4 cannot use "+mem+"M"); System.out.flush();
            callback(null);
        }
    };
    c.callback(null);
}
 
Example 19
Project: code-sentinel   File: ReplAgGUI.java   View Source Code Vote up 4 votes
void initGui() {
    Font font = new Font("Courier", Font.PLAIN, 14);
    command = new JTextField(40);
    command.setFont(font);
    command.setToolTipText("Type a Jason operation here.");
    command.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            execCmd(command.getText().trim());
        }
    });

    //mindPanel = new JTextPane();
    //mindPanel.setEditable(false);
    //mindPanel.setContentType("text/html");
    
    output = new JTextArea(5,50);
    output.setFont(font);
    output.setEditable(false);
    output.setText("Example of operations you can type:\n   +bel; !goal; .add_plan({+!goal <- .print(ok) }); !!goal; \n   .send(bob,tell,hello);\n");
    output.append("   ?bel(A); .findall(X,bel(X),L); \n");
    output.append("   .mi // to open mind inspector\n");
    output.append("   .verbose(2) // to show debug messages\n");
    output.append("   .clear // clean console\n");
    output.append("\nYou can add more agents using the button 'new REPL ag' in MAS Console.");
    
    output.append("\n");
    

    frame = new JFrame(".::  REPL Interface for "+getTS().getUserAgArch().getAgName()+"  ::.");
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(BorderLayout.NORTH,command);    
    //f.getContentPane().add(BorderLayout.CENTER, new JScrollPane(mindPanel));
    frame.getContentPane().add(BorderLayout.CENTER,new JScrollPane(output));

    frame.pack();
    int h = 200;
    int w = (int)(h*2*1.618);
    frame.setBounds((int)(h*0.618), 20, w, h);
    frame.setLocation(lastPos, 200+lastPos);
    lastPos += 50;
    frame.setVisible(true);
}
 
Example 20
Project: openjdk-jdk10   File: ResetMostRecentFocusOwnerTest.java   View Source Code Vote up 4 votes
@Override
public void start() {

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent e) {
            System.err.println(e);
        }
    }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);

    boolean gained = false;
    final Robot robot = Util.createRobot();

    JFrame frame1 = new JFrame("Main Frame");
    final JButton b1 = new JButton("button1");
    frame1.add(b1);
    frame1.pack();
    frame1.setLocation(0, 300);

    Util.showWindowWait(frame1);

    final JFrame frame2 = new JFrame("Test Frame");
    final JButton b2 = new JButton("button2");
    frame2.add(b2);
    frame2.pack();
    frame2.setLocation(300, 300);

    b2.setEnabled(false);
    b2.requestFocus();

    Util.showWindowWait(frame2);

    robot.delay(500);

    //
    // It's expeced that the focus is restored to <button1>.
    // If not, click <button1> to set focus on it.
    //
    if (!b1.hasFocus()) {
        gained = Util.trackFocusGained(b1, new Runnable() {
            public void run() {
                Util.clickOnComp(b1, robot);
            }
        }, 5000, false);

        if (!gained) {
            throw new RuntimeException("Unexpected state: focus is not on <button1>");
        }
    }

    robot.delay(500);

    //
    // Click <button2>, check that focus is set on the parent frame.
    //
    gained = false;
    gained = Util.trackFocusGained(frame2, new Runnable() {
        public void run() {
            Util.clickOnComp(b2, robot);
        }
    }, 5000, false);

    if (!gained) {
        throw new RuntimeException("Test failed: focus wasn't set to <frame2>");
    }

    System.out.println("Test passed.");
}