我正在与this dropdowns合作。
如何在模板或ts文件中检测下拉模式的状态?
答案 0 :(得分:1)
您需要调用内置函数isOpen()以获取特定下拉列表是打开还是关闭的布尔值
详细信息在API, methods section
中给出相关的 TS :
import javafx.application.Application;
import javafx.event.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.shape.*;
import javafx.scene.canvas.*;
import javafx.scene.paint.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.Group;
import javafx.geometry.*;
import java.util.List;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;
import java.util.ArrayList;
import javafx.geometry.Pos;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
public class Pro extends Application {
Text title1;
Text Somma;
Text Risultato;
double dragAnchorX;
double dragAnchorY;
public static void main(String[] args) {
launch(args);}
@Override
public void start(Stage stage) {
StageStyle stageStyle = StageStyle.TRANSPARENT;
final Stage stageRef = stage;
Group rootGroup;
TextField chosenInt;
Button closeButton = new Button("close");
closeButton.setAlignment(Pos.BOTTOM_CENTER);
closeButton.setLayoutX(100);
closeButton.setLayoutY(185);
closeButton.setOnAction(new EventHandler <javafx.event.ActionEvent>()
{public void handle (javafx.event.ActionEvent e){
stageRef.close();
System.out.println("You pressed Close()");}
});
Rectangle blue = new Rectangle(250, 230, Color.SKYBLUE);
blue.setArcHeight(25);
blue.setArcWidth(25);
title1 = new Text("Let's calculate the sum of all the n");
title1.setFont(Font.font("Verdana", FontWeight.BOLD, 11));
title1.setFill(Color.BLUE);
title1.setTextOrigin(VPos.CENTER);
Somma = new Text("Summation = ");
String res = " ";
Risultato = new Text(res);
Label output = new Label (res);
Risultato.setTextOrigin(VPos.TOP);
Label chooseInt = new Label ("until this n: ");
chosenInt = new TextField();
Button setButton = new Button("Calculate");
setButton.setOnAction(new EventHandler <javafx.event.ActionEvent>()
{public void handle (javafx.event.ActionEvent e){
String res = chosenInt.getText();
String str = chosenInt.getText().toString();
int n = 1;
try {n = Integer.parseInt(str);}
catch (NumberFormatException w) {n = 8;};
int sum=0;
int g=0;
int f=0;
ArrayList<Integer> myList = new ArrayList<Integer>();
while (g<=n+1){myList.add(g); g++;}
for(f=0;f<n+1;f++){sum+=myList.get(f);}
System.out.println("The sum off all the numbers until " + (f-1));
System.out.println("is");
System.out.println(sum);
res.concat(Integer.toString(sum));
output.setText(Integer.toString(sum));
output.setScaleX(2);
output.setScaleY(2);
} });
HBox chooseIntBox = new HBox(chooseInt, chosenInt);
VBox contentBox = new VBox(13);
contentBox.setSpacing(13);
contentBox.setAlignment(Pos.CENTER);
contentBox.getChildren().addAll(title1, chooseIntBox, setButton,Somma,
output);
contentBox.setLayoutX(15);
contentBox.setLayoutY(15);
rootGroup = new Group(blue, contentBox, closeButton);
Scene scene = new Scene(rootGroup, 270, 250);
scene.setFill(Color.TRANSPARENT);
stage.setScene(scene);
stage.initStyle(stageStyle);
stage.setOnCloseRequest((WindowEvent we) -> {
System.out.println("Stage is closing");});
stage.show();
Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
stage.setX((primScreenBounds.getWidth() - stage.getWidth()) / 2);
stage.setY((primScreenBounds.getHeight() - stage.getHeight()) / 4);
rootGroup.setOnMousePressed((MouseEvent me) -> {
dragAnchorX = me.getScreenX() - stageRef.getX();
dragAnchorY = me.getScreenY() - stageRef.getY();
});
rootGroup.setOnMouseDragged((MouseEvent me) -> {
stageRef.setX(me.getScreenX() - dragAnchorX);
stageRef.setY(me.getScreenY() - dragAnchorY);
});
}}