javafx - 禁用按钮时显示消息
问题描述
它可能在按钮被禁用后显示消息?可以绑定消息或使用禁用属性吗?有任何想法吗。例如我得到了这个:
这个想法是当按钮 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();
});
}
}
});
}
}
解决方案
我这样做,没关系。
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();
}
推荐阅读
- bash - 带有变量的 printf 没有按预期工作
- dart - 如何在颤动中更改日期和时间格式?
- sql - SQL:PostgresSQL,按两列分组和平均 - 即使平均值为零,如何显示所有组
- r - 计算具有多个变量的两个不同列的总和和频率,并使用面积图进行绘图
- swift - 如何使在 macOS 上运行的应用程序浮动在其他应用程序之上?
- apache-kafka - kafka 消费者组 ID 无法按预期工作
- javascript - 为什么我的代码显示“找不到播放器”?
- c# - 试图创建简单的 js 缩小器,但它不会删除任何东西,即使我删除了空格
- vue.js - 当按钮已经被点击时,如何禁用按钮取决于它的行?
- file - 如何使用 make 保持文件同步?