Solved

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

Posted on 2004-09-30
7
184 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
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!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

628 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