Solved

How to set a pop-up frame always on the top?

Posted on 2004-09-30
7
177 Views
Last Modified: 2011-10-03
In my program, if I click a button, it will pop-up a small frame-based window and I want to set it always on the top. How can I do that?

Assumed the frame-based window looks like:

...
JFrame myFrame = new JFrame();
myFrame.setVisable(true);
...

Besides, if I click the OK-button on this window, it will be closed or distroyed, not using setVisable(false). How to do that?
0
Comment
Question by:chenwei
[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
  • 2
  • 2
  • +1
7 Comments
 
LVL 4

Expert Comment

by:gdrnec
ID: 12193826
Do you mean you want the Frame to act as a modal dialog?
0
 
LVL 9

Accepted Solution

by:
DrWarezz earned 30 total points
ID: 12194041
To set it to be on top, try this:

myFrame.toFront();

should work. :)

gL,
[r.D]
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12197492
JDialog myDialog = new Dialog();
myDialog.setModel(true);
myDialog.show();
0
Technology Partners: 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!

 

Author Comment

by:chenwei
ID: 12199332
To DrWarezz:

It works.

Bur how about the followings:
Besides, if I click the OK-button on this window, it will be closed or distroyed, not using setVisable(false). How to do that?
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12200276
Hi chenwei,
I'm not totally sure what you mean, by:
"not using setVisable(false)"

Could you elaborate a little more? Thanks.
[r.D]
0
 

Author Comment

by:chenwei
ID: 12200447
Hi DrWarezz,

after I click the OK-button on this frame, this frame-window should close, i.e. should be deleted from the program memory. Since I don't know how to do that, I use setVisable(false). But the frame-window is still in the program-memory, right?

Is there any function like myFrame.close() ?
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12223952
add the listener to the button and call this function
frame.dispose();

use like this for X button on toolbar
frame.setDefaultCloseOperation(
                                 JFrame.EXIT_ON_CLOSE);

 
 you can also handle the closing event like this
 frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                super.windowClosing(e);
///Do some stuff here before closing
            }
        });
0

Featured Post

Technology Partners: 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

Suggested Solutions

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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:
The viewer will learn how to implement Singleton Design Pattern in Java.

763 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