Can you tell if your jframe is behind an OS window, or minimized but requesting focus?
I am writing a multi frame java program and trying to keep track of what new info the user hasn't seen yet in.
You can use methods like:
frame.isActive() to determine if the frame currently has focus
frame.getExtendedState() to determine if the frame is minimized
Of course you would to continually poll the frame for this information, so I'm not sure how helpful it will be.
Related
I am new in J2SE, I am using Java Swing to create J2SE application. The JFrame can pick and drag at any where on screen but I want to restrict frame to do not reach out from desktop screen.
How to enforce the drag restriction?
Note: The code must work for all type of O.S.(Window, Linux, Mac)
I found help from net but that code is not supportable for all type of O.S.
You will need to know size of the screen , and size of JFrame.
Toolkit.getDefaultToolkit().getScreenSize();
Use thread to scan for location of JFrame on screen. CONSTANTLY / Daemon
Find the location/Position of JFrame in the window
If user gets to corner of the screen, do some math.Set your JFrame ot latest valid location or to center of the screen.
How to set JFrame to appear centered, regardless of monitor resolution?
Bud for the love of sanity , dont do this. Just let user move it where
he wants it.If any software woud do this to me i woud consider it
borderline Malware sincei use multimonitor setup, and this is not
acceptable for me.
I would like to block the frame switch request of the user in my java Application; Example:
I have the main frame with full size and the setup frame with a smaller size (400,400 for example). While the setup frame is opened I wouldnt like to let the user to acess the Main Frame, he can do this only if he closes the setup frame.
That might one duplicated question and I'm sorry for that, but I couldnt find the specific term to research what I want, I was try something like "Window focus on java" but I think I was researching in the wrong direction..
Thanks in advance for the help
The best solution is to use a modal dialog. If this is not an option, you will have to create a handler yourself that fires whenever a frame gets focus and checks if it is the right frame. If not, the handler must focus on the important frame.
set child jframe or whatever swing component as modal window
I am loading a JFrame showing the company logo and credits etc before starting the main application. I am having some problems. Fist of all, the size of my new JFrame can never be set. The JFrame looked fine when I previewed it under netBean but came out smaller every time. I tried to do it with a new constructor and setSize(), but still not working. Second, the JFrame has been loaded very slowly. No images and everything could be loaded and the JFrame stays blank for at least five seconds, really kind of annoying. Do it have anything to do with where I put the image files?
Thanks alot.
I am loading a JFrame showing the company logo and credits etc before starting the main application. I am having some problems. Fist of all, the size of my new JFrame can never be set. The JFrame looked fine when I previewed it under netBean but came out smaller every time. I tried to do it with a new constructor and setSize(), but still not working.
It is very difficult to suss out what is wrong without seeing your code, but having said that, your comment about this being a NetBeans-generated GUI suggests that the code will be very large and hard to read and interpret. It is for this and many other reasons that I am not a fan of using NetBeans to generate GUI's, especially for newbies who are just learning how to use Swing. I suggest that you write out your GUI code by hand with some user-friendly layout managers, nested by nesting JPanels if necessary. If you do it this way, you'll have some greater flexibility and control in the construction of your GUI, and you'll also have readable and debuggable code that you can post here for our assessment and help should it not work out right for you.
Second, the JFrame has been loaded very slowly. No images and everything could be loaded and the JFrame stays blank for at least five seconds, really kind of annoying. Do it have anything to do with where I put the image files? Thanks alot.
This sounds like a threading issue. I'd just load the images for the intro GUI first, then show the intro window, and then in a background thread, load any other resources that the program needs.
Having said all this, you probably want to look into using Java's own splash screen as this may do all that you're trying to cobble together on your own. The tutorials can help you with this (please click on link above or here).
Much unclear question description though I want to point some tips...
Do it have anything to do with where I put the image files?
If you mean your JFrame title image so you can use its setIconImage() method
Fist of all, the size of my new JFrame can never be set.
It is quite strange :( because you can always write code like a
JFrame aFrame=new JFrame();
aFrame.setSize(x,y);
... to control your frame scale
Second, the JFrame has been loaded very slowly. No images and
everything could be loaded and the JFrame stays blank for at least
five seconds
It may be caused by single thread overloaded but still to analyze the problem show the main class code or its exceptions stack trace
previewed it under netBean but came out smaller every time
what component do you use to paint your logo? And how do you paint it? Show the snippet
You can set the size by right click on the jFrame and
Set Default size
(netbeans design view)
I hope this is what you want
this may be useful for you?
JPanel aa = new JPanel(new GridBagLayout());
aa.setMaximumSize(new Dimension(500,500));
aa.setMinimumSize(new Dimension(490,490));
aa.setBorder(BorderFactory.createLineBorder(Color.black));
I opened the properties dialog for my JFrame and set "minimum size" field to [500,500] but that did not work.
What did work for me was selecting the "..." button at the right of the "minimum size" property. In the "JFrame Mininumsize" dialog as follows:
set dropdown (Set forms minimum size property using: ) = "Custom Code"
set code in (Form.setMinimumSize( ) ) = "new Dimensiom(500,500)"
Link between two JFrame using JMenu
I have an application where I have to move to another frame by clicking a menu. for example, on a file menu, I click on add which will bring out a new frame where operations can be carried out. what code(s) can i use in Netbeans?
I used it to open another JFrame but when I exit the new JFrame both frames are closed ....
there is something wrong in ma code plz help me in that prob....
You have to set the defaultCloseOperation to something else then EXIT_ON_CLOSE. Please refer to the documentation for JFrame for more information. I suspect that the second JFrame should only have HIDE_ON_CLOSE though.
do you need to use jframes? why not jdialogs? (the dialog window (which can pop up) does not have to be modal.
if you have two different frames, that can make parentage (which window belongs to which frame) something you need to keep track of more assiduously.
please tell us in more detail what you are trying to accomplish; that will help in picking the correct widgets to be used. if things are hard to do/code in swing, then there's probably an easier way with other widgets/components, imho.
good luck!
how do i close a frame yet open a new frame?
i have a frame, (help)
when i click on my menu item
i want to open (mainForm)
exit from help.
new mainForm().setVisible(true);
System.exit(0);
i know this closes the whole program however how do i get it to only close the current frame
thanks
If you no longer want to use the frame you could use frame.dispose()
If you just want to hide it use frame.setVisible(false).
If you extended a Frame and are trying to close it from within use this.dispose or this.setVisible(false).
You should rethink your requirments. For the user, it would be best to have both the program and the help window visible at the same time. Closing the main window when showing the help screen and vice versa is really, really bad for usability - you shouldn't do it. We've had window-based GUIs for almost 30 years now - showing several windows on screen at the same time is what they're for!
Let's say you created your frame as so:
JFrame mainframe = new JFrame("Radio Notes");
//show Frame
mainframe.setVisible(true);
//close the frame
mainframe.dispose();
I think you should hide the frame you do not wish shown with setVisible(false). System.exit(0) stops the JVM ending the entire program.
In short, the semantics of setVisible has nothing to do with starting / stopping the application.
If you want to start an entire new application you'd have to look at Runtime.exec(). I don't really know if you can close the parent process (the Help application) with exit() though.
try setting the default close operation for the JFrame like so.
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
Then implement a WindowListener that performs the actions you want when a window closing event is fired.