I need some advice on how to write text into another application's line edit when that control receives mouse focus.
For example:
I opened google.com and clicked in the "Search" field (so the mouse focus is in "Search" field).
I need to programmatically write text in that field.
I have used Robot class but some symbols are not supported. Are there any ways to solve this problem?
Related
I've started to learn Javafx and I happened upon this "strange" feature. I've made a simple window with two buttons. When I press one of them a blue stroke appears and stays there until I press the other button. I can't find any logical use of this other than knowing which button was pressed last. Even from a UX perspective, it doesn't make sense. I've tried somehow to "deactivate" it throught CSS but no luck. Is there any solution for this?
It's hard to tell what you are searching for without the code.
But I think you are referring to the visual marker for the currently focused menu item. This function is used in situations where the user hit's the "Tab"-Key to navigate through your menu items.
You can disable this feature for items by unchecking the "Focus Traversable" option in the "Properties" Tab. This will also disable the tab navigation!
There is already a thread that has a solution for exactly this topic. See:Remove Focus Box Around TextField
It talks about disabling the focus color using css, while keeping the tab navigation feature by using this css styling rule:
-fx-focus-color: transparent;
(Source: Uluk Biy's answer in the linked topic)
The blue outline around controls in JavaFX is there to indicate which control has focus.
Focus indicators are a common idiom used across different UI frameworks, not specific to just JavaFX. In a traditional mouse/keyboard based input setup, there needs to be some indication of where a keystroke will be sent when a key is pressed. Imagine there are multiple fields on a form, a few text fields and a couple of buttons. If the user types some characters - how does the system know into which text field to insert the characters? Similarly if the user presses return to activate a button, which button will get activated? The answer is that the button or field which currently has focus will receive the input. The focus can be changed usually by pressing the tab key to tab to a new field or pressing on a different field with the mouse. However, even though the system knows that which field has focus, it is important to provide feedback to the user to let the user know which field has focus. That way when the user types, they have some idea of where there input will be directed.
What you see with a blue outline around a button in JavaFX is a visual indicator to note that the button has focus and, if you press space, that button's action will be triggered and not some other button. When you click the mouse on another button it will both trigger the other button's action and transfer focus to that button, so if you subsequently press space, the last clicked button will be actioned again.
The focus color for a controls in JavaFX that are using the default modena.css stylesheet which comes with JavaFX 8, can be controlled by a couple of css properties which you can override in the user stylesheet for your application (by defining the properties in the .root {} css style class:
/* A bright blue for the focus indicator of objects. Typically used as the
* first color in -fx-background-color for the "focused" pseudo-class. Also
* typically used with insets of -1.4 to provide a glowing effect.
*/
-fx-focus-color: #039ED3;
-fx-faint-focus-color: #039ED322;
So, for instance, you could remove all focus colors from your application using:
.root {
-fx-focus-color: transparent;
-fx-faint-focus-color: transparent;
}
However, removing focus color indicators would probably make your application much less intuitive and more difficult to understand.
Let's look at a simple form in JavaFX:
The blue ring around the text input field for User Name indicates that text input will go into that field.
Is there a proper way to disable the focus ring only from my project's buttons?
If you want to disable focus feedback only for buttons and for all buttons in a project and also not effect other controls, then you can define a stylesheet rule for that:
.button {
-fx-focus-color: transparent;
-fx-faint-focus-color: transparent;
}
Note: I still don't recommend doing this even if other frameworks you use do not provide focus rings for buttons.
This will override the default focus coloring for buttons defined in the default JavaFX 8 modena.css stylesheet. You do not need to (nor should you) modify the modena.css stylesheet to override values in it. You can just redefine the values using a more specific CSS selector rule within your application's stylesheet. If you need to understand how CSS selectors work, there are numerous resources on the web you can search for and read. Oracle provide a getting started tutorial on how you can set a custom CSS style for a scene. The relevant code line is to add your user stylesheet to your scene:
scene.getStylesheets().add(
MyApplication.class.getResource(
"my-stylesheet.css"
).toExternalForm()
);
I'm trying to create a virtual numpad in Java. The objective is to click a button (0...9) and input is reciprocated in another application with highlighted text field like notepad or calculator. In order to do that I used the robot class but it doesn't work. My code goes like this (for button click 0):
if(e.getSource()==b0){
java.awt.Robot r = new java.awt.Robot();
gui.setFocusable(false);
r.keyPress(KeyEvent.VK_0);
gui.setFocusable(true);
}
I've tried to make the JFrame out of focus on button click so that input goes to highlighted application. Is there any way I can always keep my application on top without giving it focus?
In order to show your frame on top always use:
Jframe.setAlwaysOnTop(true);
see more here
How to detect that pasting event is fired in the address bar through GWT? When we paste the thing from textbox to the addressbar then how to detect that pasting event in gwt.
What if a user decides to type an address instead of pasting it?
A standard approach is to use OnValueChangeEvent on a Textbox. It fires when a Textbox loses focus AND a value in the Textbox has changed, or when the Enter button is pressed while focus is still on the Textbox.
An alternative approach is to add a button, like "Take me there", that a user can press after a user is done entering the URL (either by pasting it or typing it).
In my Swing application I am using a bar-code scanner attached to the machine using USB port. I want to trigger an action (popup a window) as soon as some thing is scanned using bar-code scanner. I do not have any text field (e.g. JTextField) focused before the scanning is done.
But if I scan something now without any focus on text filed it is scanning and not registering the value to the application, just like how we press A,B,C,D in the keyboard without having the cursor focused on a text field region. I need to notify the application internally when the scanning happens and register the value from bar-code scanner in a text field.
How do I do this?
You can add KeyListener to any component including your window. So if at least something is in focus you will receive the events.
Moreover you can use AWTEventListener: Toolkit.getDefaultToolkit().addAWTEventListener(listener, eventMask). Play with eventMask to get events you are interesting in. This allows getting event on AWT level. Even if you have 10 separate windows in your application and want to catch events from all of them you can do it in one single place.
I have a general question. I would like to have a window containing some buttons, radio buttons, text fields and so on. So, user can do something (write text, select options and press buttons). As the result of the user activity window should change it structure/appearance some element should disappear and some appear.
How do I program such "updates"? Should I close an old window and open a new one or I can modify content of window without closing it?
After adding your components or such, calling revalidate() on your container will do the updates