Solved

Deiconify a Frame from within the application

Posted on 2000-05-12
4
237 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
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:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

742 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