With the TalkBack setting enabled, the accessibility focus shifts to the hamburger icon automatically. (makes sense since it's the upperleft component in the screen).
When a user opens my app with TalkBack enabled, I want the focus to automatically select the text in the toolbar. This way, the name of the screen is spoken out loud, instead of the drawer action.
I have added an example below:
Use this code below on your toolbar (title) object.
android:accessibilityTraversalBefore="#id/drawer"
That will solve your problem.
I managed to set the focus manually on another component by simply adding the the following field:
android:accessibilityTraversalBefore="#id/idOfTheComponentThatHasTheAutoFocus"
In this way, you make sure that this component will be called first in the traversal order.
Related
I have a ViewPager set up with a TabLayout at the top. The app is running on a device with physical d-pad directional keys that can be used to move the control focus.
How can I detect when the focus is moved to specific tabs in the TabLayout?
I can see the Tab highlight when the focus is received, but I am unable to find any events that might allow me to detect this.
Also, TabSelected doesn't work, as it doesn't fire until the center key of the d-pad is pressed to "select" the focused tab.
You can add custom view to your tab, and then setOnFocusChangeListener for this view.
In a Codename One GUI builder app when I navigate back to my Main form, the screen is always shown at the top.
How can I get the screen to auto scroll down to the part I want and retain its previous scroll?
I'm assuming that this is a GUI builder app.
Normally this should be seamless as the UI will scroll to the last focused component but if you don't have focusable elements this might be harder. You can store the scroll Y value on the exitForm event and restore it the beforeShow event using something like:
f.addShowListener((e) -> f.scrollY(yValue));
I went through GWT Showcase and I found disclosure panel.
I want to control disclosure panel collapsing and expanding by clicking on one button.
In certain situations button can be disabled, In that case I want to enable/disable button.
Please refer this for more details:
Please suggest, How to do this?
You could use setOpen, but note that you cannot disable the DisclosurePanel and prevent it from opening when clicking its header.
You might want to build a custom widget instead.
I am mucking around with a hierarchical menu trying to make it scrollable. Yes, I know about Menu Scroller at the Java Tips Weblog, but it doesn't quite do what I want, so I've been mucking about with a stripped down version of it it and I'm not quite getting it to work.
Basically I want a JMenu with too many items to display on which the user can press the up and down arrow keys to scroll the menu. I have gotten tanatalizingly close to what I want but I have come to a hurdle which I can best describe this way:
When [ENTER] is pressed while a popup menu has focus, default behavior is to do the action associated with the selected item and dispose of the menu. If the menu is nested, popups above it in the hierarchy also close (become invisible). Where is this behavior coded? I've looked all over JMenu, JPopupMenu, JMenuItem, AbstractButton and I don't see what I am looking for. Where is the Swing source code that executes this common behavior?
If I knew the answer to that, I might understand why my implementation isn't working. I can do the action, but the menu and its parents won't disappear. I can make the menu disappear by setVisible(false) of course, but I can't walk the containment hierarchy to find the parent menus and make THEM disappear.
I can do the action, but the menu and its parents won't disappear.
I think you can use:
MenuSelectionManager.defaultManager().clearSelectedPath()
I'm not 100% certain for menus, but I know for JTextComponents that all of the keystrokes (copy, paste, enter, move forward by words/sentences/lines, deleting, etc.) are implemented via the InputMap and ActionMap. JTextcomponents also use Keymaps, but I'm pretty sure those are specific to text components.
I have a JTextPane sitting in a JFrame, with a popup menu that is assigned to the JTextPane through the JTextPane.setComponentPopupMenu method.
I want to give the JTextPane a "Word-like" popup behavior. By that I mean, if you right click outside of your current text selection, the caret will reposition to where you right clicked, with menu options that affect a text selection (such as cut, copy, or bold) disabled. If you right click within your current text selection, the popup will appear with options that effect text selection enabled, the text selection will persist, and the caret will not move.
The problem is I cannot seem to find where I can put the code that handles the selection change. I tried:
Using the "PopupMenuWillBecomeVisible" event which is triggered before a popup becomes visible. The event passed into this method does not contain any mouse event information so there is no way for me to use viewtomodel to find out how to modify the selection. I could use MouseInfo but that seems dubious at best.
Using MousePressed/MouseReleased events in the JTextPane or JFrame. Apparently, neither of these events are invoked when a popup menu is triggered. In fact, I still can't determine what the parent component of my popup menu is. (I did read that in windows "MouseReleased" is the popup trigger, while in other systems "MousePressed" is the trigger. I tried both and neither worked).
So, I guess the problem is that I can't seem to find a place to put code where it would be called before the popup menu becomes visible, but has awareness of the mouseEvent that triggered the popup menu. I must be missing something here.
with a popup menu that is assigned to the JTextPane through the JTextPane.setComponentPopupMenu method.
You can use the older approach of displaying the popup based on your own custom MouseListener.
See the section from the Swing tutorial on Bringing Up a Popup Menu. Now you have access to the MouseEvent so you can convert that point to a point in the Document so you know where the click was made, on selected or unselected text.