Solved

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

Posted on 2004-09-30
7
171 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
  • 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 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:

705 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

19 Experts available now in Live!

Get 1:1 Help Now