★ wanayoo — archive 1999 http://developer.java.sun.com/developer/qow/index.htmlNouvelle recherche | Portail wanayoo
Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Question of the Week

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 

Question of the Week No. 62

Researched by Rama Roberts

Question of the Week presents answers to key questions posed by the developer community. The intent is to pass this important, but not always easy-to-find, information on to JavaTM Developer ConnectionSM (JDC) members. The questions are selected from the JDC newsgroups generally because: they are frequently asked, they are significant or timely, or their answers are not easily accessible.

Note: If you have a question to which you need an answer, try the JDC newsgroups. You can read through the existing newsgroups, or with your free JDC membership, you can post new messages or threads.

Topic:   How can I bring up an iconified JFrame?

Question:  Will someone tell me how to bring up a JFrame from the task bar without actually clicking on it? In my application, when a user tries to open up a window, my application checks for a window open already. If one is open, it will bring it up to the front.

Answer:

If you are using JDKTM 1.2.x you can use the Frame class's setState() method passing it 'Frame.NORMAL' to unminimize a frame. See attached sample working code that unminimizes a JFrame two seconds after it's been minimized.

import java.awt.event.*; 
import java.awt.*; 
import javax.swing.*; 

public class Unminimize { 
    
  public static void main(String args[]) { 
   new UnminimizeFrame(); 
    } 
} 

class UnminimizeFrame extends JFrame { 

    UnminimizeFrame() { 
	super(); 
	
	// Components should be added to 
	//the container's content pane 
	Container cp = getContentPane(); 

	/* Add the window listener */ 
	addWindowListener(new WindowAdapter() { 
	    public void windowClosing(
	                     WindowEvent evt) { 
		dispose(); 
		System.exit(0);
	    } 
	    public void windowIconified(
	                     WindowEvent evt) { 
		try {
		    Thread.sleep(2000);
		} 
		catch(InterruptedException ie){} 
		setState(Frame.NORMAL);
	    }
	}); 

	/* Size the frame */ 
	setSize(200,200); 

	/* Center the frame */ 
	Dimension screenDim = 
	 Toolkit.getDefaultToolkit(
	                    ).getScreenSize(); 
	Rectangle frameDim = getBounds(); 

	setLocation((screenDim.width - 
	  frameDim.width) / 2,(screenDim.height - 
	                   frameDim.height) / 2); 
	
	/* Show the frame */ 
	setVisible(true); 
    } 
} 

Many thanks to JDC member paternostro for contributing to this answer.


Submit your comments or answers to this question here!

Include my JDC user id in my response

See what other members have said.

[ This page was updated: 29-Oct-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.