TextFieldのOn Input Method Text Changedで、一文字入力ごとに処理をしようと思いましたが、イベントが拾えませんでした。
abcと入力した時、入力するたびに、
Text:a
Text:ab
Text:abc
と表示されるつもりでしたが、ボタンをクリックするまで何も表示されず、
ボタンクリックで、
Mouse:abc
と表示されます。
何か決定的な勘違いをしているのでしょうか?
Main.java
Java
1package sample; 2 3import javafx.application.Application; 4import javafx.application.ConditionalFeature; 5import javafx.application.Platform; 6import javafx.fxml.FXMLLoader; 7import javafx.scene.Parent; 8import javafx.scene.Scene; 9import javafx.stage.Stage; 10 11/** 12 * キーテストプログラム 13 */ 14public class Main extends Application { 15 @Override 16 public void start(Stage primaryStage) { 17 try { 18 FXMLLoader loader = new FXMLLoader(getClass().getResource("KeyTest.fxml")); 19 Parent root = loader.load(); 20 Scene scene = new Scene(root,400,300); 21 scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); 22 primaryStage.setScene(scene); 23 primaryStage.setTitle("KeyTest"); 24 25 //以下の出力はtrue 26 System.out.println(Platform.isSupported(ConditionalFeature.INPUT_METHOD)); 27 28 primaryStage.show(); 29 } catch(Exception e) { 30 e.printStackTrace(); 31 } 32 } 33 34 public static void main(String[] args) { 35 launch(args); 36 } 37} 38
KeyTestController.java
Java
1package sample; 2 3import javafx.fxml.FXML; 4import javafx.scene.control.TextField; 5import javafx.scene.input.InputMethodEvent; 6import javafx.scene.input.MouseEvent; 7 8/** 9 * メイン画面(コントローラ) 10 * @author torii 11 * 12 */ 13public class KeyTestController { 14 15 @FXML 16 private TextField srcText; 17 18/** 19 * TextFieldChanged 20 */ 21 @FXML 22 private void txtChanged(InputMethodEvent event){ 23 //↓出力されない 24 System.out.println("Text:" + srcText.getText()); 25 } 26 27 @FXML 28 private void btClicked(MouseEvent event){ 29 //↓出力される 30 System.out.println("Mouse:" + srcText.getText()); 31 } 32} 33 34
KeyTest.fxml
XML
1<?xml version="1.0" encoding="UTF-8"?> 2 3<?import javafx.scene.control.*?> 4<?import java.lang.*?> 5<?import javafx.scene.layout.*?> 6<?import javafx.scene.layout.BorderPane?> 7 8<BorderPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.KeyTestController"> 9 <center> 10 <AnchorPane prefHeight="131.0" prefWidth="332.0" BorderPane.alignment="CENTER"> 11 <children> 12 <TextField fx:id="srcText" layoutX="14.0" layoutY="14.0" onInputMethodTextChanged="#txtChanged" /> 13 <Button layoutX="174.0" layoutY="14.0" mnemonicParsing="false" onMouseClicked="#btClicked" text="Button" /> 14 </children> 15 </AnchorPane> 16 </center> 17</BorderPane> 18

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/23 07:12