点击它我正在启动一个弹出窗口。 Pop有一个带有tableview的动态创建堆栈窗口。如果我双击表中的一行或我输入esc其工作正常。 问题是,当我点击背景舞台上的任何地方时,它会给我以下错误。当我点击启动弹出窗口的舞台时,如何关闭弹出窗口。请建议。
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1435)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3324)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3164)
at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3119)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1559)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2261)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:228)
at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
at com.sun.glass.ui.View.notifyMouse(View.java:922)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:722)
以下是我的代码
public void trkTripNoBtnClick(ActionEvent ae){
StackPane st = new StackPane();
final TableView<GatePassDTO> tripListTableView = new TableView<GatePassDTO>();
TableColumn<GatePassDTO,String> colTrkTripNo = new TableColumn<GatePassDTO,String>();
TableColumn<GatePassDTO,Date> colGatePassDttm = new TableColumn<GatePassDTO,Date>();
TableColumn<GatePassDTO,String> colTruckNo = new TableColumn<GatePassDTO,String>();
TableColumn<GatePassDTO,String> colBat = new TableColumn<GatePassDTO,String>();
colTrkTripNo.setText("Trip No");
colTrkTripNo.setCellValueFactory(new PropertyValueFactory<GatePassDTO,String>("tourPlnNo"));
colGatePassDttm.setText("Gate Pass Dttm");
colGatePassDttm.setCellValueFactory(new PropertyValueFactory<GatePassDTO,Date>("gatePassDttm"));
colTruckNo.setText("Truck");
colTruckNo.setCellValueFactory(new PropertyValueFactory<GatePassDTO,String>("haulPmNo"));
colBat.setText("BAT ID");
colBat.setCellValueFactory(new PropertyValueFactory<GatePassDTO,String>("batId"));
List<GatePassDTO> tripsList = GateIn.getGatePassReference().gateIn_tourPlnNoLookUp(1);
tripListTableView.getColumns().addAll(colTrkTripNo,colGatePassDttm,colTruckNo,colBat);
tripListTableView.setItems(FXCollections.observableList(tripsList));
final Popup popup = new Popup();
popup.setX(txtTrkTripNo.getLayoutX());
popup.setY(txtTrkTripNo.getLayoutY()+txtTrkTripNo.getHeight()+30);
colTrkTripNo.prefWidthProperty().bind(tripListTableView.widthProperty().multiply(0.20));
colGatePassDttm.prefWidthProperty().bind(tripListTableView.widthProperty().multiply(0.45));
colTruckNo.prefWidthProperty().bind(tripListTableView.widthProperty().multiply(0.15));
colBat.prefWidthProperty().bind(tripListTableView.widthProperty().multiply(0.20));
tripListTableView.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent t) {
if(t.getClickCount() == 2 && tripListTableView.getSelectionModel().getSelectedItem() !=null){
GatePassDTO g = tripListTableView.getSelectionModel().getSelectedItem();
popup.hide();
txtTrkTripNo.setText(g.getTourPlnNo());
getTripDetails(txtTrkTripNo.getText());
}
}
});
tripListTableView.addEventHandler(KeyEvent.KEY_PRESSED,new EventHandler<KeyEvent>(){
@Override
public void handle(KeyEvent t) {
if(t.getCode() == KeyCode.ESCAPE)
popup.hide();
}
});
/*Label lblFind = new Label("Find");
TextField txtfind = new TextField();
st.getChildren().add(lblFind);
st.getChildren().add(txtfind);*/
st.getChildren().add(tripListTableView);
VBox v = new VBox(5);
v.getChildren().addAll(st);
popup.getContent().addAll(v);
popup.show(GateIn.primaryStage);
}
答案 0 :(得分:0)
你必须检查阶段的焦点属性......
试试这个有效的
stage.focusedProperty().addListener(new ChangeListener<Boolean>
() {
@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
if(t1==false)
{
System.out.println("focus losted");
btn.getScene().getWindow().hide();
}
}
});