on click of it i am launching a popup. Pop has a dynamically created stackpane with a tableview. If i double click a row in table or i enter esc its working fine. Issue is when i click anywhere on the background stage it gives me following error. How to close the popup when i click on the stage from where the popup is launched. Please suggest.
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)
Below is my code
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);
}
you have to check focus property for stage...
try this its worked
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();
}
}
});