首页 > 解决方案 > 禁用按钮时显示消息

问题描述

它可能在按钮被禁用后显示消息?可以绑定消息或使用禁用属性吗?有任何想法吗。例如我得到了这个:

这个想法是当按钮 genrevreq被禁用时显示一些警告信息。我正在尝试这个:

  public void mensaje() {
         if(genrevreq.isDisable()) {
             stackrevreq.focusedProperty().addListener(new ChangeListener<Boolean>()
                {
                  @Override
                  public void changed(ObservableValue<? extends Boolean> b, Boolean oldValue, Boolean newValue)
                  {
                    if(newValue == false) {

                        stackrevreq.setOnMouseClicked(ee->{
                            Text cabecera = new Text();
                            cabecera.setText("INFORMACION");
                            cabecera.setStyle("-fx-fill:red;-fx-font-weight:bold");
                            Text mensaje= new Text();
                            mensaje.setText("NO SE PUEDE VOLVER A FIRMAR");
                            mensaje.setStyle("-fx-fill:white;-fx-font-weight:bold");
                            JFXDialogLayout contenido = new JFXDialogLayout();
                            contenido.setHeading((cabecera));
                            contenido.setBody(mensaje);
                            contenido.setStyle(" -fx-background-color:  linear-gradient( from 0.0% 0.0% to 100.0% 100.0%, rgb(153,204,153) 0.0, rgb(153,204,153) 100.0);");
                            JFXDialog dialogo = new JFXDialog(stackrevreq,contenido, JFXDialog.DialogTransition.CENTER);
                            JFXButton cerrar = new JFXButton("CERRAR");
                            cerrar.setStyle(" -fx-background-color: white;-fx-border-color:  linear-gradient(to bottom, red 14%, red 91%); -fx-border-radius:  15%; -fx-text-fill: red;  -fx-font-family: Oswald;-fx-font-weight: bold; -fx-border-width: 5px;-fx-background:none;-fx-border-insets: -5.8;");
                            cerrar.setOnAction(e3->{
                            dialogo.close();
                            });
                            contenido.setActions(cerrar);
                            dialogo.show();     
                        });     
                  }
                  }
                  });
                }
              }

标签: javafx

解决方案


我这样做,没关系。

public void generarrevision() throws IOException {
            genrevreq.setOnMouseClicked(e->{
                try {
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                imagenbuffer = SwingFXUtils.fromFXImage(getimagecaptura.getImage(), null);
                ImageIO.write(imagenbuffer, "jpg", outputStream );
                outputStream.flush();
                byte[] Convierteimagenabytes = outputStream.toByteArray();
                outputStream.close();
                String Bd="jdbc:sqlserver://DESKTOP-8PJDQNJ:1433;databaseName=QUORA";
                String Usuario="sa";
                String Pass="milkas87";
                String data =reqcon.getText().toString();
                String SqlQuery="UPDATE REQUISICIONES SET REVISION=1, FIRMA_REVISION= ? WHERE CNSREQ = ?";
                Connection Conexion = null;
                try {
                    Conexion=DriverManager.getConnection(Bd, Usuario, Pass);
                    PreparedStatement ps =Conexion.prepareStatement(SqlQuery);
                    ByteArrayInputStream inputimagen = new ByteArrayInputStream(Convierteimagenabytes);
                    ps.setBinaryStream(1, inputimagen, Convierteimagenabytes.length);
                    ps.setString(2, data);
                    ps.executeUpdate();
                    Text cabecera = new Text();
                    cabecera.setText("DATOS ENVIADOS CON EXITO");
                    cabecera.setStyle("-fx-fill:red;-fx-font-weight:bold");
                    Text mensaje= new Text();
                    mensaje.setText("REQUISICION EN ESTADO DE REVISION");
                    mensaje.setStyle("-fx-fill:black;-fx-font-weight:bold");
                    JFXDialogLayout contenido = new JFXDialogLayout();
                    contenido.setHeading((cabecera));
                    contenido.setBody(mensaje);
                    contenido.setStyle(" -fx-background-color:  linear-gradient( from 0.0% 0.0% to 100.0% 100.0%, rgb(153,204,153) 0.0, rgb(153,204,153) 100.0);");
                    JFXDialog dialogo = new JFXDialog(stackrevreq,contenido, JFXDialog.DialogTransition.CENTER);
                    JFXButton cerrar = new JFXButton("CERRAR");
                    cerrar.setStyle(" -fx-background-color: white;-fx-border-color:  linear-gradient(to bottom, red 14%, red 91%); -fx-border-radius:  15%; -fx-text-fill: red;  -fx-font-family: Oswald;-fx-font-weight: bold; -fx-border-width: 5px;-fx-background:none;-fx-border-insets: -5.8;");
                    cerrar.setOnAction(e3->{
                    dialogo.close();
                    genrevreq.setDisable(true);
                    RevisionReqController.this.getThisstage().close();
                    });
                    contenido.setActions(cerrar);
                    dialogo.show();         
            }catch(SQLException ee) {
                ee.printStackTrace();
            }

推荐阅读