Java Swing - Make a window like JOptionPane - java

I've been creating GUIs using Jigloo for a game and I've run into a problem.
I would like one of my GUIs to have some properties that the JOptionPane has but I don't know how to describe it properly.
The JOptionPane, when open, doesn't allow a user to access the other open windows. It gives a ping sound and flash the JOptionPane window.
Is there a name for that? Also can I put that onto one of my GUI windows?
Thanks in advance

The JOptionPane uses a modal dialog. See How to Use Modality in Dialogs for details.

Related

Use JFrame instead of JDialog in Netbeans Wizard

I have build an application using the Netbeans Wizard Framework as outlined here and here. I have my application working properly, but the problem I have is that the application does not show in the windows taskbar. I am pretty sure the problem is that the Wizard Framework uses a JDialog instead of a JFrame, but I can't figure out if that can be changed.
If anyone has experience with this framework, please let me know if it can be made to appear in the taskbar.
Changing is quite easy.
Open the form in NetBeans.
Change extends javax.swing.JDialog to extends javax.swing.JFrame.
Save the file and close it.
Reopen the file.
In designer mode, make a change. I usually just change the name of a component.
Save the file.
Undo the change and save the file again.
You should be all set.
Wizard Framework uses a JDialog instead of a JFrame, but I can't figure out if that can be changed.
don't use more than one JFrames, this's road to the hell, you cann't to setToFront, setOwner, iconify, etc ...
use JDialog or JWindow instead with parent to the one single JFrame
use undecorated JDialog, with setModal() or is possible to set various ModalityTypes too
If anyone has experience with this framework, please let me know if it can be made to appear in the taskbar.
this Swing Framework is long time depreciated
you can use SplashScreen repeatly instead of JDialog/JWindow

Java Quaqua Popup Menu

I have a Java Swing application running on OSX that uses Quaqua. All the TextFields and TextAreas have a popup menu on right click. This must be done by Quaqua as it is not standard in Swing.
My question is:
How do I set my own Actions on the popup menu?
Please Note. This is a question about Quaqua popup menus NOT any Swing popup menu. If you are not familiar about Quaqua then please don't answer.
A pop-up menu is the same as a regular menu. The Swing tutorial about menus covers how to use them, how to insert entries, ... . Reading that tutorial should get you started
The popup menu set by Quaqua can be removed by setting a client property:
myTextField.putClientProperty("Quaqua.TextComponent.showPopup", Boolean.FALSE);
You can then add your own MouseListener to handle creating your own pop up menu.
I haven't figured out, however, to make this change global, and so I have to set the client property on each of my text fields individually, which is a bit of a pain.

Updating the GUI of a Java Applet

I'm writing a Java applet in Eclipse. When I click on the button in the applet, it should display a message, but the message won't actually show up until I fiddle with the applet window, like resizing the window. Is there something I should add in my code, so the GUI automatically updates once I click the button?
generally a call to repaint() will take care of that.
based on mre's comments, this has better information: Java Swing revalidate() vs repaint()

How to set action for close button?

I've created a stand-alone java desktop application in Netbeans 6.9. I want to set the action for the close button of my application. I want to know how and where to set the code for the action of that close button. Can anyone please help me regarding this?
You have to register an ActionListener on your close button. In this listener you can define what do to.
How add ActionListener to JButton in Java Swing
I think answers for How to close a java swing application from the code will be helpful too
Right-click on the button then, > Events > Action > actionPerformed. NetBeans will generate the action listener for you:)
Edit: If you want a close listener, then read here.
Once you have the handler working, one convenient approach is to "set the default button by invoking the setDefaultButton() method on a top-level container's root pane." See the tutorial section How to Use JButton Features for details.
I dislike to wake up the zombies but, here is what I would do (this is considering that you are working in a Window based application, otherwise this is going to be useless!!!):
I would set a window listener for the close operation here is the way to do it.
Then I will delete manually the temp folders and files...
Obviously the window listener I'm talking about would go on the last window you (as a user) should close, this would not work either if you want it to happen when the last window is closed, but there is not an order specified to do that, some workarounds for that is making all your windows to share a flag/counter to indicate if it is time to delete the temp files/folders.
Again if your application is going to work underground sometimes (I mean that you can dispose all windows without shutting down the application), or is a daemon this won't work
If you just want to exit the application when the close button is hit, you can use
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
as explained in the Oracle tutorial

JDialog Not Displaying When in Fullscreen Mode

I have an application that runs in fullscreen mode and has been working fine. Now I need to add a simple, undecorated dialog and I'm running into trouble. If I run the application maximized but not in fullscreen, the dialog displays and functions as expected. When I switch back to fullscreen, the dialog will not display.
The dialog extends JDialog and only contains a JSlider and a couple of buttons. It is undecorated and not modal. (I disabled modality for testing purposes -- it was a pain to force exit the app every time the dialog blocked input.) I'm entering full screen mode using setFullScreenWindow(), passing in the main JFrame for the app. It doesn't make a difference if I set that very JFrame as the owner of the JDialog or not. Nor does it seem to help if I call toFront() on the dialog.
The dialog seems to be active -- especially since it blocks input if I make it modal -- but just not showing or being hidden. So, is there any obvious trick to displaying a JDialog in fullscreen mode? Something I might be overlooking or omitting?
If there's no obvious solution, I can post some code later. Unfortunately, I don't have time right now.
JOptionPane.showInternalXXXDialog()
methods render dialogs as JInternalFrames.
Maybe you could consider using a JIternaFrame to simulate the dialog box.
And in fact, as M1EK alluded in his answer and I mentioned in a comment, Java applications in full screen mode will not allow other windows to show over them. The Javadoc API for GraphicsDevice reads:
Windows cannot overlap the full-screen window. All other application windows will always appear beneath the full-screen window in the Z-order.
In the end, I reconfigured my application so that it doesn't enter full screen mode until a bit later. This still gives me a fairly class presentation at the start and allows my JDialog to function as it should. The transition to full screen mode is quick and smooth, even in the "middle" of my app.
Do you really want to be in full-screen mode for this app? That's more of a gaming feature - to get more direct access to the frame-buffer, I always thought. Have you read this tutorial:
http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html
Really seems to me not to be the best choice for a Swing app with child windows.
Try to use this. Is not an exclusive full screen but it is close enough.
setExtendedState(JFrame.MAXIMIZED_BOTH);
setUndecorated(true);

Categories

Resources