我有一个 fontawesomeicon。如果我按下按钮 btStar
t,Fontawesomeicon 上就会闪烁一个红色圆圈(参见 GIF)。如果我按下按钮 btStop
它应该被禁用。
我用标签尝试过。
当我按下 btStart 按钮时,标签会在 SetVisible(true)
和 setVisible(false)
的时间间隔内发生变化。
有人能给我一个解决方案吗?先感谢您。 Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Controller .java
package sample;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import java.awt.*;
public class Controller {
@FXML
private FontAwesomeIconView iconCamera;
@FXML
private Button btStart;
@FXML
private Button btStop;
@FXML
void mouseCklicked(ActionEvent event) {
System.out.println("sad");
}
}
样本.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane alignment="center" hgap="10" vgap="10" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.141" fx:controller="sample.Controller">
<columnConstraints>
<ColumnConstraints />
</columnConstraints>
<rowConstraints>
<RowConstraints />
</rowConstraints>
<children>
<AnchorPane prefHeight="387.0" prefWidth="573.0">
<children>
<FontAwesomeIconView fx:id="iconCamera" glyphName="VIDEO_CAMERA" layoutX="130.0" layoutY="123.0" size="36" />
<Button layoutX="253.0" layoutY="93.0" mnemonicParsing="false" onAction="#mouseCklicked" text="Start" />
<Button layoutX="354.0" layoutY="93.0" mnemonicParsing="false" text="Stop" />
</children>
</AnchorPane>
</children>
</GridPane>
最佳答案
- 创建不带红点的图像 (PNG)。
- 创建带有红点闪烁效果的 GIF。
- 将这两个图像导入到您的项目中。
- 按开始键后,将图像设置为 *.GIF。
- 按停止键将图像设置为 *.PNG。
简单。不要让事情变得复杂!
关于java - 单击按钮红点应该闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50723108/