eventhandler

JavaFX TabPane disable tab switching by keys

99封情书 提交于 2019-12-23 15:40:09
问题 I have a Tab with some content: ScrollBar and other. The ScrollBar has event handler for keys: left and right . But if I press these buttons, Tabs are switched, because TabPane also has a key handler. How to disable default event handler for TabPane or change switching policy? 回答1: The problem is that a ScrollBar is not focus traversable by default and key events are only fired for focused Node s. You can set the ScrollBar focus traversable: sb.setFocusTraversable(true); sb.setOnKeyPressed(e

JavaFX ContextMenu how do I get the clicked Object?

爷,独闯天下 提交于 2019-12-22 06:10:28
问题 I am learning javafx.scene.control.ContextMenu, and right now I am facing a problem: how do I get the clicked Object from EventHandler? both event.source() and event.target() return the MenuItem. let me explain with an example: what should I write inside the function handle? TextField text = new TextField(); Label label1 = new Label("hello"); Label label2 = new Label("world"); Label label3 = new Label("java"); ContextMenu menu = new ContextMenu(); MenuItem item = new MenuItem("copy to text

Which C# pattern has better performance to avoid duplicated event handlers?

丶灬走出姿态 提交于 2019-12-21 04:05:07
问题 There are basically two patterns in avoiding duplicated registering of event handlers: (According to this discussion: C# pattern to prevent an event handler hooked twice) Using System.Linq namespace, and check if the event handler is registered by calling GetInvocationList().Contains(MyEventHandlerMethod); Do the unregistering before registering, like this: MyEvent -= MyEventHandlerMethod; MyEvent += MyEventHandlerMethod; My question is, performance-wise, which one is better, or is there a

applying an event handler to newly created objects

让人想犯罪 __ 提交于 2019-12-20 05:45:25
问题 So my goal is to have 5 boxes and every time one box is clicked a new box appears. The code I wrote for that is this: window.onload = function(){ var boxList = document.getElementsByClassName("box"); for(i = 0; i< boxList.length;i++){ boxList[i].onclick = clickHandler; } } function clickHandler(eo){ if(eo.target.style.backgroundColor != "black") { eo.target.style.backgroundColor = "black"; var box = document.createElement("div"); box.setAttribute("class","box"); box.setAttribute("id",document

Delegated event handler without jQuery

喜欢而已 提交于 2019-12-20 03:08:47
问题 Made this example: https://jsfiddle.net/d8ak0edq/2/ document.getElementById('outer').oncontextmenu = function() { return false; }; outer = document.getElementById('outer'); outer.addEventListener('mousedown', foo); function foo(evt) { if (evt.which === 1) { evt.target.style.backgroundColor = 'red'; } else if (evt.which === 3) { evt.target.style.backgroundColor = 'blue'; } } /* $outer = $('#outer'); $outer.on('mousedown', 'div', foo); function foo(evt) { if (evt.which === 1) { $(this).css(

Delegated event handler without jQuery

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 03:08:05
问题 Made this example: https://jsfiddle.net/d8ak0edq/2/ document.getElementById('outer').oncontextmenu = function() { return false; }; outer = document.getElementById('outer'); outer.addEventListener('mousedown', foo); function foo(evt) { if (evt.which === 1) { evt.target.style.backgroundColor = 'red'; } else if (evt.which === 3) { evt.target.style.backgroundColor = 'blue'; } } /* $outer = $('#outer'); $outer.on('mousedown', 'div', foo); function foo(evt) { if (evt.which === 1) { $(this).css(

javascript addEventListener not working more than once

随声附和 提交于 2019-12-20 01:46:24
问题 I'm trying to do a relatively simple javascript program/page, just 3 sliders RGB to affect the color of a square and circle. It works GREAT when I have the event listeners 'inline' with the input elements: i.e., onchange="someFunction(x,y)" However, when I move the event listeners to be in the javascript, and use addEventListener , it only works ONCE when the page loads, and then never again...almost as if a removeEventListener has been called, but I haven't done that. Yes, I made sure that

jquery dynamic binding .on() select parents or children?

六眼飞鱼酱① 提交于 2019-12-19 09:27:34
问题 For example, $( "#dataTable tbody tr" ).on( "click", function() { alert( $( this ).text() ); }); $( "#dataTable tbody" ).on( "click", "tr", function() { alert( $( this ).text() ); }); .on() binds "tr" with click event handler. The first one select children and register click event handler directly. The second one select parent "tbody", and select children "tr" as an argument. Are they both dynamic binding? Do they have the same effect? What is the difference between these two? 回答1: No, only

In Racket, is it possible to have multiple event-handlers in big-bang?

送分小仙女□ 提交于 2019-12-13 05:41:21
问题 I am wanting to do two different things at each tick. Is it possible to have multiple on-tick event handlers in a big-bang environment? This is what I would like to do: (big-bang world (on-draw show-world) (on-tick event1 event2 1)) or (big-bang world (on-draw show-world) (on-tick event1 1) (on-tick event2 1)) Neither of these methods is allowed. Is there a way to do this? Thank you. 回答1: What would it mean? For example, suppose that ;; A World is a Nat (a natural number). and here are the

Using showAndWait in the onFinished EventHandler of an Animation doesn't work

浪尽此生 提交于 2019-12-12 11:14:39
问题 In JavaFx, I want to show a modal dialog after an animation ends. For some reason, calling showAndWait in the EventHandler that gets executed after the animation ends doesn't work. A new window is shown, but it seems like nothing is drawn inside it. This example demonstrates the issue: public void start(Stage primaryStage) { Rectangle rect = RectangleBuilder.create().width(200).height(200).fill(Color.RED).build(); StackPane root = new StackPane(); root.getChildren().add(rect); Timeline