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
Related
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
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?
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 :)
I want to implement some functionality in a library and make it available as a GUI building block for my applications. I think I would like to implement it as something that extends a JPanel, so it can be embedded as a component in other windows.
Is there a reason I should use a JDialog instead? How easy is it to create a JDialog which displays a JPanel along with minimal other appropriate components? (e.g. just a border/closebox/etc for modeless dialog; for modal, the same + an OK/Cancel)
You should extend JDialog only if you want a Dialog, and if you want just a Panel that you can use in other Windows or Frames you should extend JPanel.
Yes, it is easy to create an JDialog just containing a JPanel with a border, closebox and OK/Cancel, both modal and not modal.
Have a look at How to Make Dialogs and How to Use Panels
I would make it a JPanel. That way you could reuse it in other components or drop it into a JFrame (by calling setContentPane) if you want to run it as a standalone. The only reason for you to need a JDialog is if you want to make your component modal.
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.