首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用CSS更改节点设计

使用CSS更改节点设计
EN

Stack Overflow用户
提问于 2015-04-10 01:37:49
回答 1查看 43关注 0票数 0

我不知道我在向节点添加CSS样式时做错了什么。

我有一个主应用程序窗口。然后单击菜单项,然后打开另一个模式窗口,如下所示(ModalWindow扩展Stage):

代码语言:javascript
运行
复制
FXMLLoader loader = new FXMLLoader(getClass().getResource(CONSTANTS.ROOT_USER_EDIT.string));
BorderPane editPane;
   try {
        editPane = new BorderPane(loader.load());
        ModalWindow editWindow = new ModalWindow(Main.mainStage, editPane, "Edit user");
        //its new stage with new scene, so we need to load this file again
        editWindow.getScene().getStylesheets().add(getClass().getResource(CONSTANTS.CSS_PATH.string).toExternalForm()); 
        UserData userData = (UserData)usersTable.getSelectionModel().getSelectedItem();
        UserEditWindowController userEditWindowController = loader.getController();
        userEditWindowController.fillWithData(userData);
        editWindow.initModality(Modality.APPLICATION_MODAL);
        editWindow.showAndWait();
    } catch (IOException exception) {
        ExceptionDialog exceptionDialog = new ExceptionDialog("Couldn't load UserEditWindow",exception);
        exceptionDialog.showAndWait();
    }

添加了这个CSS文件:

代码语言:javascript
运行
复制
#greenInfoTip {
    -fx-graphic-text-gap: 20;
    -fx-font-size: 44.0px ;
    -fx-background: green;
    -fx-background-color: rgb(128,255,128);
}

我尝试在根控制器类中这样做:

代码语言:javascript
运行
复制
infoTip.setId("greenInfoTip");

但没有效果。我做错什么了吗?

这里的编辑 ItachiUchiha就是它的样子:

方法在UserEditWindowController类中:

代码语言:javascript
运行
复制
@FXML
    private void buttSaveAction(ActionEvent event){
        //check if login and password doesn't contain spaces and is 4-16 characters long
        String login = textFLogin.getText();
        String password = textFPassword.getText();
        boolean hasLoginWhiteSpace = isContainingWhiteSpace(login);
        boolean hasPasswordWhiteSpace = isContainingWhiteSpace(password);
        boolean isLoginMoreThan3 = (login.length() > 3)? true : false;
        boolean isLoginLessThan17 = (login.length() < 17)? true : false;
        boolean isPasswordMoreThan3 = (password.length() > 3)? true : false;
        boolean isPasswordLessThan17 = (password.length() < 17)? true : false;

        InfoTip infoTip = new InfoTip();
        if( hasLoginWhiteSpace == false){
            if( hasPasswordWhiteSpace == false ){
                if( isLoginMoreThan3 == true && isLoginLessThan17 == true){
                    if( isPasswordMoreThan3 == true && isPasswordLessThan17 == true ){
                        //========login and password are correct
                        String query = "UPDATE users SET login = ?, password = ? WHERE employee_id = ?;";
                        try( Connection connection = Main.dataSource.getConnection() ){
                            try( PreparedStatement preparedStatement = connection.prepareStatement(query) ){
                                preparedStatement.setString(1, login);
                                preparedStatement.setString(2, password);
                                preparedStatement.setInt(3, currentUser.getiD());
                                preparedStatement.executeUpdate();

                                currentUser.setLogin(login);
                                currentUser.setPassword(password);

                                infoTip.getInfoTip().setId("greenInfoTip");
                                infoTip.showTip((Button)event.getSource(), "Saved");
                            }
                        }catch(Exception exception){
                            ExceptionDialog exceptionDialog = new ExceptionDialog("Error while loading data from database",exception);
                            exceptionDialog.showAndWait();
                        };
                    }else{ //password has less than 4 or more than 16 characters
                        infoTip.showTip(textFPassword, "no more than 16 and no less than 4 characters!");
                    }
                }else{ //login has less than 4 or more than 16 characters
                    infoTip.showTip(textFLogin, "no more than 16 and no less than 4 characters!");
                }
            }else{ //password has white space
                infoTip.showTip(textFPassword, "no spaces!");
            }
        }else{ //login has white space
            infoTip.showTip(textFLogin, "no spaces!");
        }
    }




public class InfoTip {
    private Tooltip infoTip;


    public InfoTip(){
        infoTip = new Tooltip();
    }

    private static Point2D getNodePos(Node node){  //getting node coordination on screen
        Scene nodeScene = node.getScene();
        final Point2D windowPos = new Point2D(nodeScene.getWindow().getX(),  nodeScene.getWindow().getY());
        final Point2D scenePos = new Point2D(nodeScene.getX(), nodeScene.getY());
        final Point2D nodePos = node.localToScene(0.0, 0.0);
        final Point2D nodePosOnScreen = new Point2D(windowPos.getX() + scenePos.getX() + nodePos.getX(),
                                                    windowPos.getY() + scenePos.getY() + nodePos.getY());
        return nodePosOnScreen;
    }
    public void showTip(Node node, String text){
        Point2D nodePosOnScreen = getNodePos(node);

        infoTip = new Tooltip(text);
        infoTip.setFont(new Font(15));
        infoTip.setOpacity(0.9);
        infoTip.setAutoFix(true);
        infoTip.setAutoHide(true);
        infoTip.show(node, nodePosOnScreen.getX()-30, nodePosOnScreen.getY() - 40);
    }

    public Tooltip getInfoTip(){
        return infoTip;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-10 12:21:35

问题是

代码语言:javascript
运行
复制
infoTip = new Tooltip(text); 

howTip(Node node, String text)内部。

您正在用一个新对象重写带有id的旧工具提示。试着使用

代码语言:javascript
运行
复制
infoTip.setText(text);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29551935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档