[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Deiconify a Frame from within the application

Posted on 2000-05-12
4
Medium Priority
?
261 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 300 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

Industry Leaders: 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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

649 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