Universal Robots+

JOptionPane keyboard

Hi,

I am showing a JOptionPane with an textbox like this:
image

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.