swing: make a window never lose focus [duplicate] - java

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
“Always on Top” Windows with Java
I am using JFrames
I have a window(ex-Accounts) which gets called from a button in MainMenu.
As long as Accounts is opened i want to forbid the user from accessing MainMenu(which should be visible) unless he closes the Accounts window.

This means that you need your window to be modal. JDialog can be modal, you can either mention this in the constructor like this:
new JDialog(parent, true);
or starting with Java 1.6, you can set the ModalityType:
new JDialog(parent, modalityType);

Related

Using the exit button for executing a function [duplicate]

This question already has answers here:
Java Swing adding Action Listener for EXIT_ON_CLOSE
(4 answers)
Closed 3 years ago.
I have a problem and don't find a solution.
I have two different forms created with Java Swing and if I click a Button on the first form, than the second form is setVisible(true) and the first form is setVisible(false).
When the user now clicks the X on the top right hand corner the second form should be disposed and the first form should setVisible(true).
So how is it possible to execute code when clicking the X?
Have you tried adding a actionListener to the X?
Like it's done here:
Java Swing adding Action Listener for EXIT_ON_CLOSE

How do I set a title to a jframe? [duplicate]

This question already has answers here:
Changing the JFrame title
(4 answers)
Closed 4 years ago.
I am a beginner and I designed a frame but I didn't do it manually. Instead I used the design tool in Netbeans. I am trying to set a title with the following code in my main method but I still wont get it.
...
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> {
new QueuesFrame().setVisible(true);
QueuesFrame.SetTitle("myCase senario");
});
}
Java is case sensitive, so SetTitle should be setTitle and you need to perform the operation on an instance of the frame
QueuesFrame frame = new QueuesFrame();
frame.setTitle("myCase senario");
//frame.pack();
//frame.setLocationRelativeTo(null);
frame.setVisible(true)
Instead I used the design tool in Netbeans
If you interested in become a decent developer, I would strongly recommend avoiding the form editors until you have a better grasp of how the Swing (or even JavaFX) APIs actually work - it will give you a better baseline of skills and reduce the mess that form editors get you into

Java: Set back the same JFrame [duplicate]

This question already has answers here:
How to go back to a JFrames in Java
(3 answers)
Closed 7 years ago.
When I open a new JFrame, I set the old one as false:
ExampleJFrame.this.setVisible(false);
ExampleNewJframe newOne = ExampleNewJframe();
newOne.setVisible(true);
But If I am in newOne, how do I get back to the original Frame without creating a new as I did above?
The best solution: don't go swapping JFrames; that's can be a rough design that can annoy users. Instead swap JPanel "views" using a CardLayout as per The Use of Multiple JFrames, Good/Bad Practice?.

using javafx 8 (java 8 install) How to extend Label.setTooltip Display time to 20secs (while mouse is inside Tooltip) [duplicate]

This question already has answers here:
How to control the JavaFX Tooltip's delay?
(8 answers)
Closed 7 years ago.
I have tried Using
1)
import javax.swing.ToolTipManager;
ToolTipManager.sharedInstance().setDismissDelay(20000);
at various locations in *.java file (using NetBeans IDE)
2) Creating OnMouseEnter MouseEvent Handler Override routine including:
ToolTipManager.sharedInstance().setDismissDelay(20000);
Results: No Errors, Runs fine, Except Display Time is ALWAYS 5secs!!!
I would prefer NOT creating my own Popup Control, because I like all the Behavior of existing Tooltip, except Im trying to Display Several words in Tooltips that User Needs to take Long Time to Read. Please Help!!!!!
You're calling a Swing utility class, i.e. import javax.swing.ToolTipManager, this has no control over JavaFX functionality.
According to control JavaFX Tooltip delay, this is not supported and the subject of a change request. That question also contains a reflection based 'hack' and another workaround involving popups.

Is there a way to tell if a JFrame is "Maximised" (MS Windows) [duplicate]

This question already has answers here:
JFrame in full screen Java
(14 answers)
Closed 9 years ago.
I've been Java applications on OS X, and haven't had the opportunity to fully test in different places.
There are 2 different JFrames. The second is loaded exactly in place of the first one, and as such needs to have its size and location set to the same as the first.
This works fine, but I noticed a lot of Windows users seem to maximise the first window. When the second JFrame loads, it has the same size, but is not "maximised".
Maximised windows in the MS Windows world have a slightly different state and are treated differently by the OS.
How can I tell if a JFrame is Maximised, and how can I maximise one myself?
frame.setExtendedState( f.getExtendedState()|JFrame.MAXIMIZED_BOTH );

Categories