Detect if options menu is displayed when back button is pressed - java

My back button is overridden for ... reasons. I've implemented a new feature, the options menu, and I need unique function calls if the back button is pressed while this options menu is up versus when it is not up. How can I discern if the menu is up when the back button is pressed? Thanks guys!

Use a boolean. Set it to true in onPrepareOptionsMenu(). Set it to false in onOptionsMenuClosed().

Related

How to recognise which radio button is selected before currently selected radio button?

I have two radio buttons, both added to a ButtonGroup. I have added an ActionListener for both. Suppose that at present the first radio button is selected, then again if I click on the same button then again actionPerformed() will be called. It doesn't look good. I want to prevent the call to actionPerformed() if that radio button is already selected.
One possible way could be to store current selected radio button state in a variable, but I want to know the java internal method for this.
Is there any method to do this?
if(radioButton.isSelected()) this will tell you if its selected. if it's selected you don't perform action. If it's not selected perform the action.

JFace - Remove keyboard focus from dialog

I have a ProgressMonitorDialog object which contains a cancel button. I want to disable the initial focus of the cancel button. The reason I want to remove the initial focus from the button is that a user may accidentally hit a key on the keyboard while a batch operation is in progress and cancel the whole operation. If a user wants to cancel an operation I would prefer that they press the tab key and manually set the focus, or click on the cancel button with a mouse.
From what I can tell, there is no easy way to do this. I can create another button on the ProgressMonitorDialog that does nothing and have that take focus, but that's an ugly workaround. Especially since the button has to be visible or the focus will shift to the cancel button. I have also tried overriding the method that creates the cancel button and bypassing the shell.setDefaultButton() method but no luck.
Any clues/suggestions?
If you are extending Dialog class, then you can do the following, override createButtonsForButtonBar(Composite) method, and pass in false as default button argument on the button which you don't want the initial focus on.
#Override
protected void createButtonsForButtonBar(Composite parent) {
// create OK and Cancel buttons by default
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

Un-Select JToggleButton

I have a JToggleButton, not in a group, and if it's pressed, I want to be able to Un-Select
it if I press another JButton.
I've tried using:
toggleButton.setSelected(false);
toggleButton.doClick();
but neither un-Select the toggle button, it stays "highlighted".
What can I do so that the toggle button goes back to the normal
un-Selected state, like if I pressed it again?
Is it a matter of calling the above while in the UI Thread?
jToggleButton.doClick(): Programmatically perform a "click". This does the same thing as if the user had pressed and released the button.
jToggleButton1.setSelected(false);
jToggleButton1.doClick();
If you execute this code subsequently, it is actually doing nothing. Because, as soon as the first line set the jToggleButton1 as unselected second line set it as selected. If you want just jToggleButton to be unselected use jToggleButton1.setSelected(false) by removing doClick(). But if you want to toggle among selected and deselected using your other JButton click, use jToggleButton1.doClick() only.

java radio buttons in jface automatically setting the first button to true

Here is a puzzler, every time I create a group of radio buttons in SWT/JFace, the first button is always true, but if create a standard button and call it to reset the radio button it will reset to being false.
I would like it to be set to false as default.
Has any encountered a problem like this and how to solve it?
Thanks in advance
When creating a group of radio buttons, exactly one from them HAS to be selected at a time. By selecting a different button, the first one becomes unselected. Therefor, if you set selected true to second radio button, the first will be unselected.
If you create a group of radio buttons, the first one is always selected by default. Use
secondRadioButton.setSelection(true);
to change the state...

How to disable all buttons in Java, Android

I create an app which need to disable all buttons to allow user to leave the application - back button, menu button, camera button, call button, etc, and app should have 1 button for exit. I don't know how to disable all buttons. Tell me please, thank you
The Physical buttons? No, you can't disable all of them. Home button needs to work... Android - Is It possible to disable the click of home button
Related: Android: mass enable/disable buttons
Try this: when you enter the activity, call
getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
and when you exit the activity, call
getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION);

Categories