I have a class which extends JFrame.
The steps which I am going to do after I run my code are:
Minimize the program
Click on the icon of the program from docker to reload it
Now, I would like it to display another frame to be shown while keeping the previous frame setVisible to false. The new frame is basically a login page where after I type in a password will it show the window which was previously minimized.
Related
I have a Java swing program consisting of many JFrames, I know not the best design, but it does the job.
If I open another program, for example Firefox, and maximize that window, my JFrames are not visible.
Now when I click the button on the window taskbar of one of my JFrames the JFrame popups up.
When this JFrame popups up I need check if one of my other JFrames are visible, I mean are in front of Firefox window.
I tried isVisible(), isShowing() and isDisplayable(), but they always return true even when the JFrame is below the Firefox window. That makes sense when reading the Java documentation.
But I can't seem to find a method to tells me if my JFrame is really visible in front of the Firefox window.
It puzzles me.
A JFrame covered by Firefox has the following properties:
14:50:08,129 DEBUG DrawFrame - isVisible: true
14:50:08,129 DEBUG DrawFrame - isDisplayable: true
14:50:08,129 DEBUG DrawFrame - isShowing: true
Just to explain my goal: I have multiple JFrames and when I click one specific JFrame button on the window taskbar I want to check if another JFrame is visible for the user. If it is not visible for the user (for example when covered by another program) than I want to make it visible. Making it visible is simple: WindowListener windowActivated and call toFront on the not visible frame, but of course this causes a loop when the other JFrame is activated again (calling windowActivated > toFront > windowActivated > toFront, and so on). That is why I need to check the visibility before calling the toFront method.
I'm not aware of a function in Java to check if a window is visible for the user, so going native may be the only solution.
use windowGainedFocus/LostFocus from WindowFocusListener
loop in an array of Window[] wins = Window.getWindows();, returns all Top-Level Containers in the current JVM
be sure that in loop by test if (wins[i] instanceof JFrame) { (or JDialog/JWindow ...)
I'm trying to make a simple program with Java, Swing, that shows you a Window and by clicking the button "Start" it should show you a new panel with a login interface (enter username, password, login).
I've read a question asked here that says that it's better to use only one JFrame and it makes sense because I don't want to start a new window between clicking "start" button and going to the login interface. But, how should I do this? I've created two JPanel containers named loginPanel and startPanel, but I don't know how to set visible loginPanel when the application runs, and then by clicking a button (in startPanel) set visible loginPanel (and obviously stop showing startPanel).
I'm using the graphical Swing interface that comes with NetBeans (because the IDE have greyed the zone to edit the code by yourself, IDK why).
Could anyone give me a example of what I'd like to do?
My java program has multiple classes
One Class is responsible for creating a Jframe
Another class is responsible for writing text , which will be displayed on the jframe
Then another class responsible for other functionalities and so on.
eg
new Classname.CreatedJFrame();// generate jframe
new Classname.DisplayText(); //generate text which will be displayed on jframe
new Classname.DoSomething(); this will do something else;
These above functions are being looped up.
I am taking input via jframe which will detect which key was pressed via keyboard(0-9) However the cursor does not always stays over Jframe , I have to quickly click jframe and type the input (if delayed again i have to click the jframe area to bring pointer on focus)
Is there any solution by which the focus can always be on the jframe and input can be provided any time.
Thanks in advance
I'm trying to make a swing application that whenever you click a button it transfers from one jframe to another seamlessly.
This is what code I'm using currently to hide one jframe and display the other
private void switch() {
this.setVisible(false);
new Register().setVisible(true);
}
NOW HERE'S THE PROBLEM:
lets say the person drags the window to the center of the screen, whenever the above method is called the register jframe would open on the left hand corner, and the current open jframe would hide itself. How would I make it open where the previous jframe was. Also if there is a better way to do what I'm attempting please inform me.
You could use in the second JFrame:
setLocationRelativeTo(firstJFrame);
Or you could use
setLocation(firstJFrame.getLocation());
How do i restrict access to other JFrame?
if I open my main frame and when click the button to display other jframe, the user should not be able to go back to the main frame.
how do I do that?
if i open my main frame and click the add button,
When you click the button you display a modal JDialog. Then until the user closes the dialog they won't be able to access the main frame.
try this method...
this.setEnabled(false);
Your question is not clear to me but as per my understanding I believe You want to open a dialog on button click but when you click the button a new JFrame is displayed and it becomes impossible for you to get back to the original frame.
Use a dialog /pop-up on your button click like JOptionPane.
If you want to open a JFrame on button click, making a HOME button on the newly created/opened JFrame and linking that button to main JFrame might be a good option.Closing the newly created JFrame will display the originally created JFrame anyway.
Use a dialog (JDialog class) instead and make it modal.
Here is some help on how to do this:
http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html
Regards,