Hi,
I am showing a JOptionPane with an textbox like this:
This is the code:
String s = (String)JOptionPane.showInputDialog(
frame,
"Complete the sentence:\n"
+ "\"Green eggs and...\"",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
icon,
null,
"ham");
Do you know how to call the keyboard factory to write in the textbox?
It needs to set eventhandler which call keyboard factory.
Please try the following.
I tested on real robot (UR3 SW3.12.0).
private void onClick_btnDialog(InputEvent event) {
if (event.getEventType() == EventType.ON_PRESSED) {
KeyboardInputFactory keyboardfactory;
final KeyboardTextInput keyboard;
keyboardfactory = api.getInstallationAPIProvider().getUserInterfaceAPI().getUserInteraction()
.getKeyboardInputFactory();
keyboard = keyboardfactory.createStringKeyboardInput();
JPanel panel = new JPanel();
JTextField textfield = new JTextField(60);
textfield.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
final JTextField text = (JTextField) e.getSource();
keyboard.show(text, new KeyboardInputCallback<String>() {
@Override
public void onOk(String value) {
text.setText(String.valueOf(value));
}
});
}
});
panel.add(textfield);
JOptionPane optionPane = new JOptionPane(panel);
optionPane.setBorder(new LineBorder(Color.BLACK, 2));
JDialog dialog = optionPane.createDialog(null, "TEST");
dialog.setModal(false);
dialog.setVisible(true);
}
}
2 Likes
OOh Thanks you very much!!
Important point:
If dialog is shown, please set modal “false”.
dialog.setModal(false);
If modal is “true”, you can show keyboard but cannot input.
Best regards.
Hello @fujikit,
Firstly let me say thank you for you sample.
I am certain that is working like you have specified but I have a different use case.
I have a Dialog window already with a text field and I want just to add the possibility to write in that text field.
When I copy from you sample just the parts which I need I have an error on the line below:
keyboardfactory = api.getInstallationAPIProvider().getUserInterfaceAPI().getUserInteraction()
.getKeyboardInputFactory();
api is signaled as wrong and I do not understand why.
I have imported the Installation Api Provider and still no use.
Below my code which is causing this issue:
KeyboardInputFactory keyboardfactory;
final KeyboardTextInput keyboard;
keyboardfactory = api.getInstallationAPIProvider().getUserInterfaceAPI().getUserInteraction()
.getKeyboardInputFactory();
keyboard = keyboardfactory.createStringKeyboardInput();
textField.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
final JTextField text = (JTextField) e.getSource();
keyboard.show(text, new KeyboardInputCallback<String>() {
@Override
public void onOk(String value) {
text.setText(String.valueOf(value));
}
});
}
});
textField = new JTextField();
textField.setBounds(132, 296, 530, 110);
getContentPane().add(textField);
textField.setColumns(10);
Thank you very much in advance for your help and time!
Hi @vl4dutz_1,
Have a look at this sample, more specifically at the MyDaemonProgramNodeContribution.java file. You should get a good idea on how to correctly use the apiProvider.
Hi alexander,
Thank you for you idea, I will take a look and come back with a feedback.
Thanks!
I have the sample for creating custom dialog with keyboard feature.
Please refer here too.
Hello ,
Thank you very much for your help. Finally I have found a working solution just by copying from your examples from Contribution and View all the things regarding keyboard.
It seems that my mistake was I did not include in the Service class the API Provider.
Maybe if someone has some time can please explain to me in simpler terms,why do we need to have 3 separate files for un Urcap? I saw some examples with just one file, how they are build?
I have very little to no experience in OOP.
Thank you very much again for the time and the help!