Question about JFrames - java

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 :)

Related

Turn off JFrame

how can I turn off the first jframe after clicking a jbutton to open a second jframe? just like this.
this is what I want to happen in my GUI:
It sounds like you are talking about implementing a 'GlassPane'
A GlassPane is a technique where you place a new RootFrame layer over the existing components and use it to
Absorb all of the mouse events to prevent them from interacting with the components
Shade the UI to draw more attention to the other modal window or other frame
You can read about creating a glasspane/rootpane
and there are plenty of examples of its usage
A Swing application should only contain a single JFrame.
For the child window you can use:
a modal JDialog for a complex window when you want full control over the components on the dialog.
a JOptionPane for a easy to use pre configured "confirm" dialog. See: How to Make Dialogs for examples.

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 display other JFrame without opening new window

I'm not sure if this has been answered or the correct way of phrasing it, but have had no luck in my search. I have 4 JFrame guis all in their own classes: a main gui and 3 others. I want to know if it is possible to display the other guis inside the same window without opening a new window and setting the first window to a false visibility? I'm able to call the other JFrames and make them display through a series of actionlisteners, but they open another window, making me have to setVisible(false) the gui window. I want to be able to have all the guis display in the same window without opening/closing windows. Thanks
You should not be creating separate frames. Just create separate panels and swap the panels.
See the Swing tutorial on How to Use Card Layout for more information.
Also, if you ever do need more than one window, you should be using a JDialog for the child windows. An application should only have a single JFrame.

swing: JPanel vs. modal/modeless dialog?

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.

Keep JFrame on top of others

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.

Categories

Resources