Solved

Deiconify a Frame from within the application

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now