In other words, how can I make it so that the window or screen that they are on is the only screen that they can interact with. For example, if the user wants to exit from the screen but then wants to go to another screen, well then they will have to exit from the exit window first before they can do anything else. A better example is when you open multiple windows in Windows and try to exit from another screen than the one you're on, it will make a beeping noise indicating that you can't do that. Something similar to that is what I'm trying to achieve
It's important to note that my program consists of java code, FXML and a little bit of CSS
If you just want a frame to block all other frames from receiving events, use a modal Dialog.
Related
Is there a possibility to prevent a JOptionPane dialog from blocking the interaction with the rest of the program, especially child JFrames? In my GUI, I launch a JFrame and want a message dialog to pop up after the child is closed to remind the user of something, but they launch parallel and the reminder blocks the child frame from being used.
Like here:
popupObjMan newPopup1 = new popupObjMan(gatewayAbstract, gatewayAbstractID);
JOptionPane.showInternalMessageDialog(this, "REMINDER: DO REFRESH");
I've tried to set the popup always on top, but this doesn't quite do the job.
I have no problem with them launching parallel (I'd even prefer it), but I could not work my head around it yet.
I just started Java programming ,so sorry in case that'd be something obvious.
A JOptionPane normally need to be modal. It shows something important and waits till the user answers with whatever option you give him (e.g. ok-button, yes/no-buttons, ...)
But there are several ways to reach your target.
(a)
Normally a JOptionPane creates a modal window.
You need a modeless window which does not block other windows.
https://docs.oracle.com/javase/tutorial/uiswing/misc/modality.html
(b)
You can start different threads to work for your different windows. They can have windows which are shown whenever the responsible thread commands them to. This is a bit difficult and can lead to memory-troubles.
(c)
You can write your own message-panels (e.g. notificaton) which are shown when and how long you like.
Bigger projects use different of these ways to achieve their goals.
A JOptionPane is a component, just like a JPanel. As a component it can be added to any other panel.
The JOptionPane API provides static methods to create a show the JOptionPane on a modal JDialog by default. You can't change this behaviour.
However, you can manually add the JOptionPane to a non-modal JDialog that you create. This is extra work as you now need to handle the closing of the dialog and processing the clicked button.
If you really want to do this then read the JOptionPane API. There is a section on Direct Use which demonstrates the basic code needed to add the JOptionPane to a JDialog.
String cmd = "start calc.exe";
Process process = Runtime.getRuntime().exec(codeString);
I can call calculator out, but I wish to specify a accurate position like (200,300).
how can I rewrite my cmd String?
I know that java.awt.window can set a window or frame to the specific position.
Is there any method I can use to fill frame or window with my process?
There is no clean pure java solution because JDK does not provide API that can control non-java windows. So, if you want to can use JNI/JNA.
But I can suggest you a patch that will typically work.
Windows OS allows moving windows using keyboard. Try the following manually:
Win+R
type calc and press enter
press alt+space
press M
press enter
now use arrows to move the window. Press ESC to exit this mode.
All these actions can be implemented using java.awt.Robot.
So, you can run calculator and then immediately move its window where you want.
Well, this is not clear solution, but very simple one.
Expected Problems:
Alt+space is mapped to other, custom application
Other window that started together with calc overlaps it.
User will see that window is created somewhere and then quickly moved.
So, everything depends on how important all this for you. This solution is good as an exercise or demo but bad for real commercial application.
I am currently developing a project with a genetic algorithm.
It works fine, I get the results I wants, so no problem on this side.
I displayed all the information in the console so I decided to create a GUI to improve the software.
I have two frames. One is a selection frame where you select your options for the run.
The other is a frame with a textArea. The purpose of this second frame is to display the information about the run in it. For both frame I used the MVC design pattern. It works fine, I have run some tests for the GUI and all is displayed normally.
Now the problem is when I try to integrate the two sides.
I launch my first frame in the main. Then it switch to the second frame and run the Genetic algorithm when the information are complete and the user clicked the OK button. I make verification of the information and let the button enabled false until it is correct ;).
In theory it is suppose to display the second frame empty then launch the GA then input text in the frame dunring the run with the MVC model.
The problem happens when I click the button, the second frame display partially. I mean I have the frame with the title and the red close button but there is nothing in it. I can move the frame with my mouse but if i click the red close button, nothing append, so I guess the frame is kind of freeze. The Ga run perfectly during this time. At the end of the
GA's run the rest of the frame appears with all the information that should have been input in it. So the Mvc model is working good. It is just the frame that don't display normally.
I use the following code :
Vue2 vrga = new VueLorsRunGa(); //create the 2nd frame
vue1.dispose(); //destroy the first one
//code to run the GA
I am not use with the GUI so maybe I made it wrong and so I don't free something needed.
If we take it sequentially, the vue2 is supposed to be totally launch before the ga code is executed. But i read in a article that the GUI's things are managed in a special thread. And so it not suppose to be freeze by the GA ... The GA got its specific threads but I haven't done any for the GUI.
So if anyone had a idea where I can be wrong or how to managed to suppress my bug, it would be great :)
Thank you for help
Scyn
You are probably running your code in the EDT thread (like directly from the actionPerformed method) which blocks other events being processed.
You should move long running operations out of the EDT thread
I'm currently working on a Java project application for University and it already has a login screen of which loads when the program is ran, and then goes on to the relevant other interfaces.
Anyway, I was wondering how I could have a window to appear for maybe 3 seconds, before the login screen loads, which would simply show the logo of the software (just like you see on Office programs when you first open them and the small window before the main document comes up). Would it require the use of threads to make the window close automatically?
Thanks,
Steve
I was always wondering what pattern is that (i guess now its name is splash screen java) when running a java desktop application and getting that window in the middle of the screen witch seems to be doing somthing (but what exactly...) and witch in some apps annoyingly stays on top and hides other stuff.
To answer your question you could just draw a title window centered and with disabled pannel for the close/maximize/minize buttons and go sleep for 3 seconds Thread.sleep(3000L) then hide the window and continue to the login screen
Or you could while showing the title window do something useful instead of just waiting and start a new Thread to initializing other gui-elements and other stuff that your application might need and wait for that thread to terminate using Thread.join(). When the thread terminates you can hide the window and proceed to the login screen. Thea waiting time would be in this case the time needed for init routine
Also you could consider just putting the logo an title somewhere in a corner on the login screen.
As a user of that software i would not apreciate to wait 3 seconds just watching a logo especialy when the application does nothing.
Hope this helps
Wow, what a stupid question you might say. But is it possible? I have a mouse move event in a Jpanel and it works even when the application is not in focus, now can I have something like that for the clicking event or something similar. And most importantly I don't want other apps (even something like the main menu) to lose focus when i click on my app.
I thought of the system's event queue but i'm not sure where that would lead me to.
Thanks in advance.
[EDIT - the purpose]
I want to create an app that mimics the users interactions with the system in a later time. for example a user takes the mouse and clicks and writes and my app will mimic that in say 2 hours time. ofcourse i would need a system hook for the outer events but i wanted to avoid os-dependant code so i basically capture the screen, take it to my app,for example the user clicks on an icon in the captured picture and then for making that come to life, i translate the coordinates to the real icon and click it (with a Robot) and in this way i can capture the user's events in my own app. the problem occurs when the user clicks on the main menu or right clicks (he's doing that in my app, and my app does that to the system so my app is in between) and ofcourse the real main menu will lose focus when the user tries to click on one of it's items.
sorry for my english.
I'm still not sure I follow what you are trying to do. But the concept of an app getting focus when you click on it is fundamental to the GUI and I suspect rather difficult to get around.
I just found this:
Focusable Windows
To support palette windows and input methods, client code can prevent a Window from becoming the focused Window. By transitivity, this prevents the Window or any of its descendants from becoming the focus owner. Non-focusable Windows may still own Windows that are focusable. By default, every Frame and Dialog is focusable. Every Window which is not a Frame or Dialog, but whose nearest owning Frame or Dialog is showing on the screen, and which has at least one Component in its focus traversal cycle, is also focusable by default. To make a Window non-focusable, use Window.setFocusableWindowState(false).
In this doucment http://java.sun.com/j2se/1.5.0/docs/api/java/awt/doc-files/FocusSpec.html
That sounds like it might do what you want.