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()
Related
Does a Java Applet always execute its code even when it losts focus? I've to put this applet in a web page.
I'm tryng to understand this cause i've to develop an applet that listen to some hardware components through JavaPos. I have a callback method defined inside the applet and i'm not sure if it works even when users click on other page component.
Thanks
Does a Java Applet always execute its code even when it losts focus?
Yes, unless of course the applet code intentionally stops execution on loss of focus.
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.
I have an applet running in a browser tab. When I switch to a different tab in the same browser, or ALT-TAB to another application entirely, the applet loses focus. When I return to the browser tab, the applet doesn't gain focus again. Is there a nice way to make this happen?
I assume it's a JavaScript change that's needed, not in the applet itself? Some onFocus handler perhaps? If it's relevant, our applet is created using an HTML <applet> tag.
I believe java has the requestFocus() method. It's in the Component class, so your JPanel or whatever you are using may be able to use this.
For the javascript part, this is what a quick googling reveals: http://www.raditha.com/java/javascript.php. I hope it helps you!
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
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);