个性化阅读
专注于IT技术分析

JavaFX PasswordField

点击下载

但是, 对于用户来说, 在文本字段中输入密码并不安全。应用程序必须使用特定的组件才能从用户获取密码。

可以通过实例化javafx.scene.control.PasswordField类来创建Passwordfield。 PasswordField类包含一个名为setPromptText()的方法, 用于在密码字段中向用户显示提示文本。用getText()方法检索在passwordfield中写入的数据。

例:

package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class PasswordFieldTest extends Application {

	
public static void main(String[] args) {
launch(args);	
}

@Override
public void start(Stage primaryStage) throws Exception {
	// TODO Auto-generated method stub
	Label user_id=new Label("User ID");
	Label password = new Label("Password");
	TextField tf=new TextField();
	PasswordField pf=new PasswordField();
	pf.setPromptText("Enter Password");
	Button b = new Button("Submit");
	GridPane root = new GridPane();
	root.addRow(0, user_id, tf);
	root.addRow(1, password, pf);
	root.addRow(5, b);
	Scene scene=new Scene(root, 300, 200);
	primaryStage.setScene(scene);
	primaryStage.setTitle("PasswordField Example");
	primaryStage.show();
}
}

输出:

JavaFX PasswordField
赞(0)
未经允许不得转载:srcmini » JavaFX PasswordField

相关推荐

评论 抢沙发

评论前必须登录!