user interface examples - mycourseville-default.s3.ap
TRANSCRIPT
KeyPress in TextArea
Pressed Key and “Ora!” keep on growing as we keep pressing!
What if we want the event to fire just 1 time!? (see
later)
Mouse Drag in TextArea!
Nothing happens!
But it works when you are dragging the left most side
of the area!
Make sure you understand the actual
meaning of events inside a component!
KeyPress inTextArea, how to fire the action only once?
Use booleancondition to check?
Set the boolean on key press and reset it on key release
[KeyTrigger.java]
But it’s a compile error!!
Cannot use local variable!
Solution 1: use a class variable instead
[KeyTrigger01.java]
Only 1 Ora! while we keep pressing key “d”.
But “d” is still increasing since the text area is
editable.
Solution 2: use a listener that remember the trigger status
[KeyTrigger02.java]
Yes. You can write your own
handler (implements
from an existing one).
What you need to do.
Source Destination
setOnDragDetected• Call method
startDragAndDrop and indicate its transfer mode (COPY,MOVE,orLINK)
• Copy data to transfer onto dragboard(clipboard for drag-and-drop)
setOnDragOver• Call method
acceptTransferModesindicating its transfer mode (COPY,MOVE,orLINK). The transfer mode must match the source.
setOnDragEntered
setOnDragExited
setOnDragDropped• Call method
setDropCompleted
Visual feedback
setOnDragDone• Clear original data if
necessary.
Source: setOnDragDetected to initialize.
Copy content as a ClipBoardContent
and put it in our drag board.
Consume event so that it does not get passed on to other
related nodes.
Destination:setOnDragEnteredand setOnDragExitedto provide Visual Feedback
Source must not
come from itself. Must verify
that data has a correct
type.
Destination: setOnDragDropped
This is what happens when the mouse is released on the destination (DRAG_OVER must work and transfer mode must also be compatible).
Must be called, or the drag is never
success.