我正在制作一個簡單的庫應用程式,并且在構建登錄螢屏時遇到以下 3 個問題。
[登錄視窗][1][1]:https://i.stack.imgur.com/ZB7jJ.png
問題 1:啟動應用程式時,我無法輸入文本欄位,但我可以突出顯示它們。
問題 2:為我的 2 個文本欄位提供的提示文本未顯示(應該是用戶名和密碼)
問題3:我的按鈕在屬性中沒有被禁用時不可點擊
這是我當前的代碼。
風景
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="489.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Login" textFill="#a49f9f">
<padding>
<Insets bottom="100.0" left="100.0" right="100.0" top="100.0" />
</padding>
<font>
<Font size="38.0" />
</font>
</Label>
<Button fx:id="LoginBtn" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="28.0" prefWidth="133.0" style="-fx-background-color: #0078D7; -fx-background-radius: 0;" text="Login" textFill="WHITE" GridPane.rowIndex="3">
<GridPane.margin>
<Insets bottom="50.0" left="100.0" right="50.0" top="50.0" />
</GridPane.margin>
</Button>
<TextField fx:id="usernametxt" layoutX="110.0" layoutY="248.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="25.0" prefWidth="274.0" promptText="Username" GridPane.rowIndex="1">
<padding>
<Insets bottom="50.0" left="50.0" right="50.0" top="50.0" />
</padding>
<GridPane.margin>
<Insets bottom="50.0" left="100.0" right="50.0" top="50.0" />
</GridPane.margin>
<font>
<Font name="Arial" size="12.0" />
</font>
</TextField>
<TextField fx:id="passwordtxt" layoutX="10.0" layoutY="148.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="25.0" prefWidth="274.0" promptText="Password" GridPane.hgrow="NEVER" GridPane.rowIndex="2" GridPane.vgrow="NEVER">
<padding>
<Insets bottom="50.0" left="50.0" right="50.0" top="50.0" />
</padding>
<GridPane.margin>
<Insets bottom="50.0" left="100.0" right="50.0" top="50.0" />
</GridPane.margin>
</TextField>
</children>
</GridPane>
控制器:
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
public class HelloController {
@FXML
private Button LoginBtn; // yes this is the same as my fxid
public void onLoginBtnClick() {
LoginBtn.setDisable(true);
}
}
最后是應用程式本身
package com.inholland.nl.eindopdracht;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 489, 400);
stage.setTitle("Login");
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
uj5u.com熱心網友回復:
問題 1 和 2 是由文本欄位中的過度填充引起的,這不允許任何空間來鍵入任何文本。移除填充物。
問題3對我來說沒有出現。請注意,您沒有在 FXML 中指定控制器,因此實際上沒有執行任何代碼。添加fx:controller="com.inholland.nl.eindopdracht.HelloController"
到GridPane
元素。
另請注意,在使用布局窗格時,您不應指定布局坐標。
以下 FXML 有效:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="489.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.inholland.nl.eindopdracht.HelloController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Login" textFill="#a49f9f">
<padding>
<Insets bottom="100.0" left="100.0" right="100.0" top="100.0" />
</padding>
<font>
<Font size="38.0" />
</font>
</Label>
<Button fx:id="LoginBtn" onAction="#onLoginBtnClick" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="28.0" prefWidth="133.0" style="-fx-background-color: #0078D7; -fx-background-radius: 0;" text="Login" textFill="WHITE" GridPane.rowIndex="3">
<GridPane.margin>
<Insets bottom="50.0" left="100.0" right="50.0" top="50.0" />
</GridPane.margin>
</Button>
<TextField fx:id="usernametxt" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="25.0" prefWidth="274.0" promptText="Username" GridPane.rowIndex="1">
<GridPane.margin>
<Insets bottom="50.0" left="100.0" right="50.0" top="50.0" />
</GridPane.margin>
<font>
<Font name="Arial" size="12.0" />
</font>
</TextField>
<TextField fx:id="passwordtxt" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="25.0" prefWidth="274.0" promptText="Password" GridPane.hgrow="NEVER" GridPane.rowIndex="2" GridPane.vgrow="NEVER">
<GridPane.margin>
<Insets bottom="50.0" left="100.0" right="50.0" top="50.0" />
</GridPane.margin>
</TextField>
</children>
</GridPane>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/517098.html
下一篇:注入點有以下注解:@org.springframework.beans.factory.annotation.Autowired(required=true)