JavaFx按钮样式

时间:2016-11-01 21:54:00

标签: css javafx

我有问题从外部css文件向按钮控件添加样式,我尝试这样的事情,例如button.getStyleSheets().add(".../... .css");

我试图选择一个按钮controll,而不是多个按钮。我想从外部css文件设置样式到按钮,我会在某处改变代码工作(我可以修复它,通过ObservableLis list = button.getStyleSheets() ; .......)但我无法将外部文件添加到按钮。

//when I click left mouse button,selected them and if I type delete key delete him 
                else if(e.getButton() == MouseButton.PRIMARY && e.getClickCount() == 1)
                {
                    //Ako se stisne taster delete da se izbrise dobavljac
                    universal_dobavljac.addEventHandler(KeyEvent.KEY_PRESSED, (ee) ->{
                        if(ee.getCode() == KeyCode.DELETE)
                        {
                            //Potvrda za brisanje dobavljača
                            ButtonType da=new ButtonType("Da", ButtonBar.ButtonData.OK_DONE);
                            ButtonType ne=new ButtonType("Ne", ButtonBar.ButtonData.CANCEL_CLOSE);
                            Alert alert=new Alert(Alert.AlertType.CONFIRMATION,"Da li želite da obrišete "+dob.getNaziv_firme()+ " dobavljača?",da,ne);
                            alert.setHeaderText(null);
                            Optional<ButtonType> result=alert.showAndWait();
                            if(result.isPresent() && result.get() == da)
                            {
                                //brisanje iz tilepane
                                tilePane.getChildren().remove(universal_dobavljac);
                                //brisanje  dobavljaca iz baze
                                try{
                                    transaction=session.beginTransaction();
                                    session.delete(dob);
                                    transaction.commit();
                                }
                                catch(HibernateException ex)
                                {
                                    if(transaction != null)
                                    {
                                        transaction.rollback();
                                    }
                                }
                                Alert alertt=new Alert(Alert.AlertType.INFORMATION);
                                alertt.setHeaderText(null);
                                alertt.setContentText("Uspešno ste izbrisali "+dob.getNaziv_firme()+" dobavljača");
                                alertt.show();
                            }

                            }
                    });
                    ////////////////

                    //THIS comments bellow don't works  -> Path is good,I check at least hundred times
                  //universal_dobavljac.getStylesheets().add(getClass().getResource("Finansije/Dobavljaci/kada_je_selektovan_dobavljac.css").toExternalForm());
                  universal_dobavljac.setStyle("-fx-font-weight: bold; -fx-font-size: 36px; -fx-font-family: Book Antiqua;   -fx-pref-width: 303px; -fx-pref-height: 230px; -fx-background-image: url(\"Finansije/icon_hover.png\"); -fx-background-color: transparent; -fx-cursor: hand");
                   universal_dobavljac.addEventHandler(MouseEvent.MOUSE_EXITED,(event) ->{
                       //universal_dobavljac.getStylesheets().add(getClass().getResource("Finansije/Dobavljaci/kada_je_selektovan_dobavljac.css").toExternalForm());
                       universal_dobavljac.setStyle("-fx-font-weight: bold; -fx-font-size: 36px; -fx-font-family: Book Antiqua;   -fx-pref-width: 303px; -fx-pref-height: 230px; -fx-background-image: url(\"Finansije/icon_hover.png\"); -fx-background-color: transparent; -fx-cursor: hand");
                   });

                }

问题在于如下。

0 个答案:

没有答案