How do I get "Goodbye Window" to show up in Java? - java

I have a Java network application and this is what I want to do:
After user logs out, his interface window closes.
Now, I want for another window to show up that will say something like: "Thank you for using our application".
This final window should be borderless and without any available option, more like a plain picture (jpeg? why not?). By clicking on it, user will be sure to close this final window.
I googled and couldn't fin anything on this matter, it's hard to phrase the question.
I hope someone helps me...

https://docs.oracle.com/javase/1.5.0/docs/api/javax/swing/JWindow.html
A JWindow is a borderless, undecorated JFrame (no titlebar or buttons).
This should be what you need.

This should help:
http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
You're interested in the windowClosing and windowClosed events

You have various possibilities, depending on when you want this dialog to display :
if you want it to display juste before the app closes, use addShutdownHook
if you want it to display when the last window closes, use addWindowListener
You can then use a JWindow with your image inside, and use addMouseListener to wait for the user to click on it.

Related

Login without multiple windows

I'm using Windows builder for create an application in Java. I create a frame with the login interface. What i want is that if the user insert correct information he will write something.
I don't want to open another JFrame I would like that the Login frame will be substitute with another one in order to have only one windows.
Could you tell me the correct object that I must use?
The best options are using either a JOptionPane or a JDialog
JOptionPane works as a message box, and can be customized to your linking and usage. For example, if what you wanna show is a sucessfully logged in message, you could use:
JOptionPane.ShowMessageDialog(null, "Logged in sucessfully", "Logged in", JOptionPane.INFORMATION_MESSAGE);
You can find out about each parameter here. It's a pretty complete documentation of the JOptionPane.
JDialog is another time of window used by Window Builder, and is works as a window that cannot be switched, a classic modal dialog. While this screen is in usage you cannot acess others (as your JFrame), unless you command it to close. And to use this you can simply create it as you would with your Frame. It's modality is set by default.
From what I get of your message the first option would be the best alternative, but that decision's up to you.
I highly recommend you to look into some Window Builder documentation before you'd resort to Stack Overflow. This would be helpfull, it explains everything you need to know about the usage of Window Builder's windows and it's funcionalities.
you can close your current frame by using the command
this.dispose();
this will just close your current window. Just make sure you open the other window too.
JFrame frame = new [yourClassname]();
that should work just fine :)

active window without showing it or bringing it to top

I want a function that I can't find wish allow to activate a window, without showing it.
If this window is a subclass of java.awt.Window you can call setVisible to hide it.
Finally found the answer:
a minimized window can't be active, and there is a way to communcate with hidden windows (if not minimized using messages)

modal parentless JDialog does not grab focus

We have an application which, as its first UI action, displays a modal JDialog without a parent frame.
public LoginDialog(Frame owner, Config config, Object... params) {
super((Frame)null, true);
It unfortunately has the annoying characteristic that when it appears, although it comes to the front, it does not grab the focus.
So the user, after launching the application by double-clicking on the start menu, has to use the mouse to select the "login" dialog and type in information.
Is there a way to make this JDialog grab the focus when it appears in the front?
I've tried calls to "requestFocus" before, after and via invokeLater "during" the call to setVisible(true) - but none of these seems to have any effect.
How do we make a modal dialog grab the focus?
UPDATE: The issue was the code used to try to present a background "wait window". This window was displayed "behind" the login dialog as a hack so that when the dialog disappeared the user would see the "Please wait" message. As it was the first window created by the application, it got the focus. I am not sure if there would have been a way to make the dialog gain the focus again inside the event dispatch thread with this hack - but I fixed it by un-hacking it and doing things properly.
First, it a little strange that modal dialog is parent-less. The point in modal dialog is that it is displayed on its parent and does not allow to access parent.
So, the first recommendation is to make it non-modal. I believe it will work.
BTW I have just tried to create such dialog and have not problems with focus. Try probably to simplify your code:
JDialog d = new JDialog();
d.setSize(200, 200);
d.setVisible(true);
This works for me and I believe will work for you. Now start changing this simple code towords your real application code. At some point it will stop working and you will see where the problem is.
If nothing helps try to use the trick I described in this article. Look for title "Portable window activation". I hope it will help.
See Dialog Focus for a potential fix using a RequestFocusListener. I have used it successfully for setting focus in JOptionPane dialogs.
1) you have to create JDialog contents and showing container wrapped inside invokeLater()
or best and safiest way is
2) you have to set for ModalityTypes or Modal for parent
3) only one from containers could be Modal in applications lifecycle

How to make a java swing popup window with combo box and 2 buttons?

I need to make a popup box with with a combo box and a couple of buttons. Please could someone advice on the best way to achieve this? I've had a look around and all I can find is alert boxes. Is this possible or will I need to create a whole new frame?
You can use the JOptionPane to achieve this. Please refer to the link below which explains this with sample code:
http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#input
JOptionPane.showInputDialog may be good enough if you are willing to leave how exactly the options are presented up to the UI.
I need to make a popup box with with a combo box and a couple of buttons
1) don't use another JFrame as popup window, use JFrame with JOptionPane/JDialog/JWindow these container are same as JFrame, but can take parent and owner
2) don't forget to setParent
3) depends if you needed decorated window then use JDialog, don't forget look for setModal() or ModalityTypes, if undecorated then use JWindow
4) don't create lots of JOptionPane/JDialog/JWindow on fly, becasue there Object are still in JVM memory, create this Container once and re-use that (by removing child) for another Action

how do i open a frame from my menu bar

i've made a menu bar with netbeans.
in the menubar i've got
file >exit
Help >Help F1
>about
the problem is i don't know how to link up either help or about to another frame that has everything i want the user to see.
can someone please tell me how to go to a new frame once eiher help or about is clicked?
thanks
For About, you would typically use a modal dialog, i.e. a JOptionPane - using those is pretty straightforward. For Help, you don't want a modal dialog, but a new separate JFrame. But you don't have to "go to" it - just create it and call show() - that's all you need to do. Like modern GUIs in general, Swing does not have an explicit control flow through or between masks. The GUI is shown, and only when the user interacts with it is your code in the various event handlers called.

Categories

Resources