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.
Related
I want to create this element in swing:
As you can see the element is a small grid of buttons which appears when i click on another button. I've tried to use JComboBox to create this element. But as far as i know, JComboBox can just render an image of the some button, but it will not behave itself as a button. Also I couldn't set a GridLayout to JComboBox.
I also tried to create some JDialog, but I suppose that's bad idea.
So the question is: Which swing's component should I use to create mentioned element?
You could use dialog in the best way to achieve this.
JDialog dialog = new JDialog(owner);
dialog.setModalityType(Dialog.ModalityType.MODELESS);
dialog.setUndecorated(true);
You could set Modality type to Modeless to avoid parent frame lock and set undecorated true to make jdialog without close option. But note that you need to close the dialog from program.
I created a JDesktopPane inside of which there is a menu.
When user clicks on the menu, a JInternalFrame appears.
The JInternalFrame carries data in a JTable and also has some JButtons
What I want to do is to prevent losing focus from JInternalFrame when user tries to click on the menu. The user has to close this JInternalFrame first.
I've read some interesting articles that proposing to use modal JDialog. But as far as I know, they cannot be that customized (or can?).
So, could anyone please help me on this?
Thank you in advance
I am testing some code using JWindow and that hide jframe, so I have to create minimize, maximize and close buttons for user friendly. How can I set state to frame when click on created buttons.
See JFrame#setState. You can do:
myFrame.setState(Frame.ICONIFIED)
As the implementation of a listener of the buttons.
I have read some of those similar threads here but they did not help me.
I have my JDialog that is undecorated and initially is unfocusable:
super(connectionsTree.getMainFrame(), "", false);
super.setUndecorated(true);
super.setFocusableWindowState(false);
super.setFocusable(false);
super.getContentPane().add(scrollPane);
super.pack();
Now whenever this dialog is visible and user tpes Space button I must make that JDialog focused so that it receives key events.
I do it like so :
if (keyCode == 32) {
tooltip().setFocusable(true);
tooltip().setFocusableWindowState(true);
tooltip().requestFocusInWindow();
}
This code makes my JDialog focusable but JDialog is not focused and key events are not grasped by it.
tooltip() method only returns instance of my JDialog.
How to make my JDialog receive focus programmatically?
Thank you!
According to documentation of requestFocusInWindow() focus to Component will be granted only if top level parent component is focus owner. So this will not work if your main window has no focus on it. You should use Component#requestFocus() instead.
From Component#requestFocus() description
Requests that this Component get the input focus, and that this Component's top-level ancestor become the focused Window.
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