dialog inside of a JInternalFrame - java

I have a JInternalFrame and I need to get some Information from user (a JFileChooser & two JTextfield).
Using another JInternalFrame, application continues running and doesn't wait for input.
How can I open a JDialog as a internal dialog?

Dialogs that are internal frames should be implemented using JInternalFrame (or JOptionPane) not JDialog

Related

Access a modeless JFrame while a modal JDialog is visible?

Is it possible to access a modeless JFrame while a modal JDialog is visible?
I have a JFrame which shows my log lines. When i display a modal JDialog, for example to login, the user can't click the JFrame.
The JFrame isn't a parent/owner of the JDialog.
The JFrame is the first JFrame being created.
Note that when i do something in the JDialog that causes a log line to be added to the log i can see it appear in the JFrame.
Is this how it supposed to work or is it possible to let the user click the JFrame while the modal JDialog is visible?
If the dialog is application modal, e.g., ModalityType.APPLICATION_MODAL, then it will block user interaction with all other top-level windows in the application while the dialog is visible. This does not prevent the application itself from changing the other top level windows states, including any text that they display.
It seems that using ModalityType.DOCUMENT_MODAL is the answer.
Give the JDialog ModalityType.DOCUMENT_MODAL (setModalityType) and make sure setModal is false. The JDialog should also have owner/parent Window.
The JFrame that should always be accessible should have no relation to the JDialog, so don't use it as owner/parent for the JDialog.
Now the JDialog blocks the owner/parent Window but the JFrame is still accessible while the modal JDialog is displayed.
Thanks go out to #Hovercraft Full Of Eels for pointing me to ModalityType.

JInternalFrame custom on-screen keyboard

I'm trying to create an on-screen keyboard using JInternalFrame, but I'm having an obvious problem. Whenever I click a button on JInternalFrame I lose focus on the text field from the main window (a custom Component). Can I somehow prevent JInternalFrame from gaining the focus?
I'm trying to create an on-screen keyboard using JInternalFrame,
Don't use a JInternalFrame.
Instead use a non modal JDialog. Then you can use:
dialog.setFocusableWindowState(false);
to prevent the dialog from gaining focus.

Focussing in Java swing

I'm developing an application using java swing. When I click a button, I want another window to be opened. This works fine. But it is possible to alt+tab to the original window and then interact with it even after the new window is open. Is there any way not to let the user focus the original window after the new window appears? By window I'm referring to Jframe/Jdialog.
Assuming the instance of your main JFrame window is called mainWindow:, the following code will prevent switching the focus.
// the second parameter makes the dialog modal and will prevent
// switching the focus to the mainWindow
JDialog dialog = new JDialog(mainWindow, true);
...
dialog.setVisible(true);
Documentation on JDialog: http://docs.oracle.com/javase/6/docs/api/javax/swing/JDialog.html
You may try to use a JDialog instead of JFrame and pass the instance of JFrame to JDialog constructor
You may also try to check
frame.setAlwaysOnTop(true);
or may be like this:-
frame.toFront();
frame.setState(Frame.NORMAL);

Exiting out of one of two JFrame exits out of both

I have two seperate JFrames but when i click the X in the topright of one, it will exit out of the other also. I have an "exit" button near the bottom to do setVisible(false), but i still have the tendency to use the x button. How would i make it so that it doesnt cancel out of the entire project?
Also, how would i make it so that the second JFrame locks out of the other JFrame untill the second JFrame is closed, like how a popup message works
Don't give your GUI two JFrames. The GUI ideally should have only one GUI. If a separate window is required, then make it a dialog such as a JDialog, and this won't happen.
Also, how would i make it so that the second JFrame locks out of the other JFrame untill the second JFrame is closed, like how a popup message works
You are perfectly describing the behavior of a modal JDialog or JOptionPane. Just use 'em.
Later we'll chat about using CardLayouts to swap views in a single GUI.
Edit, you state:
Im using Netbeans form editor to create them faster but I only see JFrame and JPanel. Can I edit them in Netbeans? I'd rather not do them through scratch Java
You've touched on another zealous belief of mine, that this is yet another reason not to use a code generator when learning a library as one can get too tied into the code generator, that it prevents one from learning the library. I strongly advise you to put aside your code-generation tool and create by hand, referring to the tutorials and API. Then later when you get more familiar with the library, sure use the tool. By the way, an answer to your direct question here is to gear your GUI's to create JPanels, and then use these JPanels where and how you want them -- in JFrames, or JDialogs, or JOptionPanes, or swapped in CardLayouts, or JTabbedPanes or nested in other JPanels,... etc...
You should be using a modal JDialog, not a second JFrame, because JDialogs provide certain functionality such as not adding another window bar to the taskbar, and automatically setting focus when the parent JFrame receives focus. Modal JDialogs prevent user input to the JFrame while it's open, useful for an "Are you sure you want to exit?" dialog, for example.
As for one JFrame exiting the other, you probably have their default close operation set to EXIT_ON_CLOSE. If you do this:
jframe.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
jframe.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
handleUserWantsToCloseWindow();
}
});
Then you can control what happens when the user wants to close, such as popping up a "Save Changes?" modal JDialog or "Are you sure you want to quit?" modal JDialog. Note that you have to manually dispose of the JFrame if you use this method.

Java Swing. Windows in front launched from JDialog

The thing I want to implement is the next UI hierarchy in my Swing application.
Main Window (JFrame)
Modal dialog (JDialog) in front of this window. It's opened by clicking on the button in main window.
The set of windows in front of modal dialog (2). They should be independent from each other and non-blocking for modal jdialog (2).
How can I code this?
Specify the owner when you create the JDialogs. Read the JDialog API for the proper constructor to use. I would guse the owner of the dialog in point 3 would be the dialog in point 2.

Categories