Keep JFrame on top of others - java

I am in a situation where I create a frame FrameB from my main frame FrameA. When the user is working on FrameB I would like it to be on top of FrameA even when the user accidentally clicks on FrameA.

Do you have to use a JFrame?
If you use a JDialog instead of a JFrame and assign FrameA as the owner of the dialog through the constructor it will always remain on top of the frame. (Example: How to set the JFrame as a parent to the JDialog)
Otherwise you can use setAlwaysOnTop() from the window class, but this can be dependent on the operating system/window manager.

You could consider making FrameB a JDialog instead of JFrame, and set it modal.

Related

JAVA - How do I make the user be able to utilize only the frame on top?

When two JFrames are enabled, I want the user to be able to use only one in the top (think of that like an error pop up on your screen, when you can't press anything but the popup itself). I am aware of the class JInternalFrame and I chose not to use it for my program. Thanks in advance :)
Use JDialog, you can set your main frame as the JDialog's parent frame, so that whenever your main frame and JDialog will display, you will be able to click only the JDialog, not your main frame.
You want a modal behaviour, then. I think you can try using JDialog instead of JFrame, something like:
JDialog dialog = new JDialog(parentFrame, title, true); //parameters: owner, title and modal
dialog.getContentPane().add(somePanel);
dialog.pack();
dialog.setVisible(true);
You can read more about it here: http://docs.oracle.com/javase/tutorial/uiswing/misc/modality.html

How to make a Frame-like component modal to JInternalFrame and block only that JInernalFrame

To make it short - my application's main JFrame has 2 JInternalFrames. In one of them, I want to have a JButton which will open a JDialog (/JOptionPane/JInternalFram). I want to set the JDialog modal to that JInternalFrame - I want to block that JInternalFrame and leave the other one accessible. I couldn't achieve this using JDialog as it only accepts Frame, Window and Dialog as owners (and it's not possible to cast from JInternalFrame to Frame). I tried using JOptionPane which accepts JComponent as a parent, but unfortunately it blocks the whole main JFrame. How can I achieve the desired behavior?

Make JFrame modal or show JDialog on taskbar

I have a JFrame that sometimes I need it to act as a frame with it's own task-bar icon, but also I need to use it as a JDialog without task-bar icon and modal of a parent frame.
Is that possible? I don't know how to implement it, so I can't put any code.
I finally solved it by making the main component a JPanel and then embedding it in a JFrame or in a JDialog.
Thanks for the idea Andrew Thompson

Change jFrame to jDialog?

I've been trying to change a jFrame to a jDialog so it inherits the icon of the main window but I don't have a clue how to do that. I tried setting it's code from public class jSemestriala extends javax.swing.JFrameto public class jSemestriala extends javax.swing.JDialog but that didn't change the icon of the window. Any ideas? I'm using NetBeans 7.0.1
The JDialog takes its icon from the owner frame.
You have two options:
Create an invisible JFrame, set your icon to it and set that frame as owner of the dialog.
Create the Dialog, get the owner, and set the icon to it.
I would choose the first option, it seems saver to me. The second one makes use of the (shared) owner of the dialog. This could cause side effects.
For further reading.
But if you already have an main frame, you simply need to set it as owner in the constructor of the dialog.
You need to specify the "main window" frame as the owner of the JDialog:
// ownerframe is a JFrame;
JFrame ownerframe = new JFrame();
JDialog dlg = new JDialog(ownerframe);
JDialogs have owner frames. The frame is either created for you if you call the constructor new JDialog(), in which case the frame is invisible; or you supply it to the dialog in its constructor using new JDialog(ownerframe).
create a new jdialog
hard copy the components from design view of jframe(you can use navigator window to copy all in clearly. ofcourse just copy the components under jframe)
paste it on jdialog(again use navigator window . ofcourse paste under jdialog)
hard copy the source code from jframe's source code window
paste it on jdialog's source code
do not touch the automaticly created codes
if you need it, add them again by using design window.
fix the errors in source code window of new jdialog by using your eyes and hands :)
remember all the time: be careful about choosing the type of class form.
sorry for my english.
it could take a long time but it will work.

Question about JFrames

I am running Windows. When you run an application on Windows, you get a button task bar where you can click it to maximize and minimize it. Is it possible to create a JFrame without this or some other component that has the functionality of a JFrame but without adding it to the task bar.
Use a JDialog instead of a JFrame. On a JDialog, you can set the 'modal' property, which means no 'upper bar' or anything is displayed.
Do make sure the JDialog has no parent frame or anything though: a modal JDialog will block the GUI of any parent GUI component. But if you just use it as your main component there is no problem :)

Categories

Resources