Solved

Deiconify a Frame from within the application

Posted on 2000-05-12
4
241 Views
Last Modified: 2008-02-01
Does anyone know how to deiconify an iconified frame from within the Java Application?
0
Comment
Question by:lvantine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 75 total points
ID: 2805164
You can use Frame.setState(Frame.NORMAL) to restore an iconified frame programatically. Here is a simple example which will restore a frame to normal 5 seconds after it has been iconified.

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

class RestoreFrame implements Runnable {
    JFrame frame;

    public RestoreFrame(JFrame frame) {
        this.frame = frame;
    }
    public void run() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            frame.setState(Frame.NORMAL);
        }
    }
}

public class IconifiedTest {
    JFrame frame;

    public IconifiedTest() {
        frame = new JFrame("Background test");
        frame.getContentPane().setLayout(new GridBagLayout());
        frame.addWindowListener(new WindowAdapter() {
            public void windowIconified(WindowEvent e) {
                Runnable r = new RestoreFrame(frame);
                new Thread(r).start();
            }
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        JButton iconify = new JButton("Iconify");
        iconify.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.setState(Frame.ICONIFIED);
            }
        });
        frame.getContentPane().add(iconify);
        frame.setSize(400,300);
        frame.show();
    }

    public static void main(String[] args) {
        IconifiedTest app = new IconifiedTest();
    }

}
---------- end ----------

Best regards,
Jim Cakalic
0
 
LVL 7

Expert Comment

by:Sasha_Mapa
ID: 2805277
LOL, Jim, a complementary example on using Runnable, threads and listeners! I say you should give Jim some more points, lvantine.
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2805312
I do what I can :-)
Jim
0
 

Expert Comment

by:Ash_
ID: 2805436
And that's a lot!!!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question