how to get rid of visual effect when disabling buttons in java - java

When I'm setting the button to be disabled using this:
jButton.setEnabled(false);
then there is this visual effect visible on the second element ->
How can I disable the button, but keep the the look of the first element?

how to get rid of visual effect when disabling buttons
Companies spend millions of dollars to develop a UI can is common and can be used by all users.
How is the user suppose to know that the button is disabled if there is no visual indication?
Anyway, (rant finished) you can manually set the disabled icon:
button.setDisabledIcon( button.getIcon());
If you also happen to have text on the button the text will still be disabled so instead of a disabled icon you can use a custom ButtonModel:
button.setModel( new DefaultButtonModel()
{
#Override
public boolean isArmed()
{
return false;
}
#Override
public boolean isPressed()
{
return false;
}
});

Related

Android Accessibility, how to remove all Button Actions?

On Android, TalkBack announces "Double tap to activate, double tap and hold to long press".
How can I remove all these default actions and just have it say nothing?
While ignoring whether that is a good idea or not for now.
Update the below code seems to not do anything:
private class NoActionsAccessibilityDelegate : View.AccessibilityDelegate
{
public override void OnInitializeAccessibilityNodeInfo(View host, Android.Views.Accessibility.AccessibilityNodeInfo info)
{
base.OnInitializeAccessibilityNodeInfo(host, info);
foreach (var action in info.ActionList.ToList()) //to list ensures we are not iterating while modifying the readonly ActionList property
{
info.RemoveAction(action);
}
}
}
If your 'view' does not have a click action but for some reason the system detects it as clickable, use the following, (I am using Xamarin for my implementation and the code to disable actions is as follows):
myView.Clickable = false;
myView.LongClickable = false;
Yes that will disable interaction with the view, but in my case the view is not meant to be interactable to begin with. For some reason the system thinks it has an action though it does not.

Validate CTabFolder before switching tabs

In a CTabFolder, I'd like to check the content for unsaved data before the user can switch from one tab to another. SWT does not provide a PreSelection event, as stated here.
I found a workaround, suggesting to switch back to the old tab when a selection is triggered, validate the data and then perform the desired switch again, if data is valid.
I do understand the general idea of this workaround, however, it is not working for me. oldPageIndex and newPageIndex do always have the same value, though I did not click on the same tab.
this.tabContainer.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
int oldPageIndex = tabContainer.getSelectionIndex();
int newPageIndex = tabContainer.indexOf((CTabItem)event.item);
// Here: oldPageIndex == newPageIndex
...
}
});
Is this workaround still working or is there anything I could possibly be doing wrong? Or maybe, has there been any fix for a real PreSelection event in the meantime? I tried using event.doit, but the SelectionEvent is fired, when the tabs have been switched already.
You can use the selection listener but as you have found the getSelectionIndex() does not give you the old tab. So you will have to maintain the old tab index yourself.
This is the technique used by the Eclipse FormEditor.

How do I change the focus on buttons of JFace WizardPage?

I have implemented a JFace Wizard with 2 WizardPages.
By default, the first WizardPage has these 4 Buttons:
Back (disabled)
Next (focused)
Cancel
Finish (disabled)
Now I want to set the default focus on the Cancel Button. How do I do that?
Removing the focus and setting it to some Control of the page's content would also be ok.
I tried setting the focus to a Button in the content layout of the WizardPage, but this only sets me a second focus on the immediateButton. The focus on the Next button is still there, and the Next button reacts to pressing enter, which is what I want to avoid.
#Override
public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) {
immediateButton.setFocus();
}
}
How can I access the Dialog buttons and change their focus?
The Next button does not actually have focus, rather it is the Shell Default button.
The logic in WizardDialog makes either Next or Finish the default button and there does not seem to be a way to change this.
You may be able to override this by calling getShell().setDefaultButton(button) in your wizard page.
Update: Testing this you can do it in setVisible but you need to use Display.asyncExec to make the code run at the right time:
final Shell shell = getShell();
shell.getDisplay().asyncExec(() -> shell.setDefaultButton(immediateButton));
above is for Java 8, for Java 7 or earlier:
shell.getDisplay().asyncExec(new Runnable()
{
#Override
public void run()
{
shell.setDefaultButton(immediateButton);
}
});

Android AccessibilityDelegate force reading of ViewGroup not children

I'm using a viewpager which is made up of some number of relative layout siblings which are quite complex.
If I click on the relative layout, it will highlight the entire page and read the title and a few textviews one after the other as expected.
If I scroll the viewpager I'd like talkback to read the next page in the same way it reads the first if I click. Secondly, if I scroll to the second, third, etc. pages and click on those layouts, talkback will read as expected.
I am trying to achieve the click behavior after the scroll event has completed.
Here is what I have for the accessibilityDelegate.
viewPager.setAccessibilityDelegate(new AccessibilityDelegate () {
#Override
public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
View page = viewPager.getCurrentPageView();
performAccessibilityAction(page, AccessibilityNodeInfo.ACTION_CLICK, Bundle.EMPTY);
}
return super.onRequestSendAccessibilityEvent(host, child, event);
}
});
I've verified that 'page' is the RelativeLayout parent that I think it is. I've also confirmed that the onRequestSendAccessibilityEvent is being fired, but it doesn't read the contents of its children. Am I missing something?
Updated
I've also tried using
viewpager.getCurrentPageView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
The above worked for another example when I needed to force talkback to reread a single item but does not have any affect if I try it on the page.
Thanks
Some background -- When you tap on the relative layout, TalkBack generates speech based on the layout's contents. On ICS, this is triggered by a HOVER_ENTER event. On Jelly Bean, it's triggered by an ACCESSIBILITY_FOCUS event. These events are sent automatically by the framework and should, generally speaking, never be sent manually from an app. The same goes for FOCUS events, except in the special case of custom views (see Accessibility talk from Google I/O 2013 for more details).
So, back on topic.
You can control the speech for SCROLLED events by populating the outgoing event with the text you want read. The down side of this is that you'll need to manually generate the text you want read, and it's very likely that this text will differ from what TalkBack will read if the user touches the layout.
viewPager.setAccessibilityDelegate(new AccessibilityDelegate () {
#Override
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
event.setContentDescription(/** your text */);
}
}
});
Another option is to do nothing and let the user explore the view on their own. This is the preferred interaction model for Android accessibility.
Edit: Video URL is broken, Changed.
This issue was reported on google check
where ViewPager does not set AccessibilityEvent parameters properly
when scrolling.
But after releas of Android Support Library, revision 23.2.1 (March 2016) This issue has been resolved.
update Support Library to Android Support Library to 23.2.1
I had the same issue before. And now I add android:focusable="true" to the ViewGroup, the TalkBalk will read the ViewGroup, instead of its children

Get Active Tab in SWT TabFolder

I apologize if this question is too basic, but I just can't figure out how to do this. I have a SWT TableFolder with two tabs, and I need to determine which of those two tabs are currently active, as it effects the behavior of another part of the program. Is this possible? Thank you in advance.
To you mean the org.eclipse.swt.widgets.TabFolder (CTabFolder)?
If yes add an eventlistener to your TabFolder(CTabFolder object
tabFolder.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
tabFolder.getSelection()[0]; // This should be your TabItem/CTabItem
}
});
If you simply have a javax.swing.JTabbedPane then calling
yourJTabbedPaneVariableName.getSelectedIndex()
gives you the index of the selected Tab

Categories

Resources