In my application I have a frame, with toolbar (the toolbar contains some actions).
I want the toolbar to be visible only when the window is focused.
So, I registered a windowFocusListener on the window.
The problem is-
when the window is not focused and I click on the place where a tool bar action should be- the action is performed.
This happens because the WindowFocusGained is called before the mouse button is released and when the mouse button released it calls the actionPerformed.
Does anybody has any idea for a work around for this problem?
Does anybody know how to determine wether the mouse button is clicked now?
You could add a MouseListener to the window, and check if the toolbar is visible in the mousePressed event. If the toolbar is not visible at the time the mouse is pressed, set a flag on the toolbar (something like "ignoreNextAction").
In the toolbar, check that flag in your actionPerformed event handler.
Reset the toolbar flag in the mouseReleased event on the window, so that the next click will work correctly.
This is assuming the mouseReleased event on the window happens after the actionPerformed on the toolbar (not sure about this). Worst case, you can work with a timer which resets the flag 50ms after the mouse event.
You could now only hide the toolbar when the window loses focus, but also disable all buttons with setEnabled(false), then re-enable on focus gain. Alternatively, synchronize setEnabled(..) with the visibility of the buttons (instead of the window focus).
Related
I am using a full-screen flipview to allow a background to rotate behind a set of inputs. if you tap the input textbox, the SIP keyboard appears.
however, tapping outside of the textbox does not dismiss the keyboard as expected. I finally realized it is because of the flipview. I verified this by adding a 250 margin around the flipview. if i tap in the area covered by the control it still doesn't dismiss, but if I tap the areas covered by the margins (that is, outside the flipview) the SIP does dismiss as expected.
I tried setting IsTabStop to false and IsTapEnabled to false for the flipview, but the SIP still remains active unless i tap outside the flipview.
since we need the flipview to be full screen, I need to know if there is a way to disable the control so that it closes the keyboard.
can this be done? which property or event on the flipview can I leverage to make this happen?
aha, by handling the "tapped" event I did the old trick of disabling and enabling the flipview and sure enough the keyboard dismissed!
I have a Button on my windows phone application. I have the Command Button binds to my RelayCommand in my ViewModel:
<Button Command="{Binding DoSomethingCommand}" CommandParameter="aString"/>
I see DoSomethingCommand get invoked correctly when I press the Button.
But when the keyboard is launched, I need to click the button twice before I see the DoSomethingCommand get invoked. The first click causes the keyboard to close, the second click invokes DoSomethingCommand.
Can you please tell me why there is a change in behaviors when the keyboard is open or not?
I came across the same issue today.
To explain it a bit better: a text box is focused, the keyboard is visible and a button is below the text box. Tapping this button the first time, unfocuses the text box and closes the keyboard. Tapping the button a second time, triggers the tapped event.
To solve this, I set MyTextBox.IsEnabled to false and then back to true in the next line. Setting it to false, unfocuses it. Setting it to true again, makes it usable again. The user won't notice, the keyboard closes and the button is tappable the first time.
Alternatively, one can set the focus to the button after leaving text box focus.
I'm trying to make a button in AS3.0, and I want it to be activated ON CLICK, not ON RELEASE..
For now I have used "MouseEvent.CLICK" and what it basically does is that it activates the button after I'm releasing/taking off the finger from mouse. And I want it to be activating when I'm pressing on it.
I need this for the application on Android, the thing is that when I touch the button on the screen, it's not reacting UNTIL I take off my finger.
Thanks a lot in advance!
You need to use an event called MouseEvent.MOUSE_DOWN
I'm looking at this:
http://www.netmagazine.com/tutorials/create-page-flip-effect-html5-canvas
However, I have one problem with that - I need to be able to click on the pages, even the edges, without triggering the page turn. I want the pages to turn when a button outside of the canvas is pressed. Is this possible using the base they provided, or do I need to go an entirely different direction?
Yes that can be done.
From what i can see, you need a click event that doesnt trigger the page drag. You need to assign a flag for this.
Let Drag = mouse drag/mouse move, down = mouse down, release = mouse release events respectively.
Initialize your flag variable as false. When a drag event is encountered it becomes true. Otherwise it remains false. As long as it is false when the mouse release event occurs it can be treated as a click. Thats the basic principle behind using mousedown and mouseup as a click event.
You will have to use e.srcElement or e.target to give you the element your cursor is currently positioned over inorder to trigger click functions relative to that element.
If you want a more detailed explanation on the page flip technique then check this out. Helped me lot.
My apps pops up a dialog. Users usually want to switch back and forth between this dialog and the application window for a period of time. I want this dialog to stay on top, so that it doesn't get hidden behind the main application window. But at the same time I want the dialog to have a minimize button so that it can get out of the way if it's not needed for a while.
Here is what I've tried:
use a modeless JDialog - the dialog stays in front nicely, but it doesn't not have a minimize button, and it doesn't have its own taskbar button either
use a JFrame - the dialog now has a minimize button and its own taskbar button, but when the main window gets focus the dialog is hidden behind it.
use a JFrame and add WindowListener.windowDeactivated() { this.toFront() } on the dialog. The problem with this is that toFront() also sets the focus, so that you get a weird focus flickering effect.
use a JFrame with setAlwaysOnTop - this is the neaerest solution, but now the window will stay on top of all other applications, not just my application.
It would be easy if toFront just brought the JFrame to the front without changing the focus, but unfortunately that is not the case. Is there another way to change JFrame Z-order?
edit: It just occurred to me that if there were an easy way to "roll-up" a JDialog, i.e. minimize it but not to the taskbar, that would solve my problem too.
Why not listen for the focusGained event in the frame and then use setZOrder/toFront on the dialog at that point? (Not sure this will work but worth a shot).