FXML

编程入门 行业动态 更新时间:2024-10-27 02:26:15
本文介绍了FXML - 按钮单击时文本字段向右移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试制作一个关于管理餐厅预订的程序,但是我有一个持久的故障,到目前为止我还没能解决。

I am trying to make a program about managing reservations in a restaurant, but I have an enduring glitch that I have not been able to fix so far.

看在这些代码中:

Customer.fxml

<?xml version="1.0" encoding="UTF-8"?> <?import javafx.geometry.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.text.*?> <GridPane xmlns:fx="javafx/fxml" alignment="center" hgap="10" vgap="10" prefWidth="300" prefHeight="300"> <padding> <Insets top="25" right="25" bottom="10" left="25"/> </padding> <Label GridPane.rowIndex="0" GridPane.columnIndex="0" text="Name"/> <Label GridPane.rowIndex="1" GridPane.columnIndex="0" text="ID"/> <Label GridPane.rowIndex="2" GridPane.columnIndex="0" text="Phone Number"/> <Label GridPane.rowIndex="3" GridPane.columnIndex="0" text="Bringing..."/> <TextField GridPane.rowIndex="0" GridPane.columnIndex="1" fx:id="name"/> <TextField GridPane.rowIndex="1" GridPane.columnIndex="1" fx:id="id"/> <TextField GridPane.rowIndex="2" GridPane.columnIndex="1" fx:id="phonenumber"/> <TextField GridPane.rowIndex="3" GridPane.columnIndex="1" fx:id="bringing"/> <Button GridPane.rowIndex="4" GridPane.columnIndex="0" text="Assign Table" fx:id="notedetails"/> <HBox GridPane.rowIndex="4" GridPane.columnIndex="1" alignment="BASELINE_RIGHT"> <Button text="Back" fx:id="back"/> </HBox> <Text GridPane.rowIndex="5" GridPane.columnIndex="0" fx:id="noted"/> </GridPane>

CustomerController.java

@FXMLController(value = "/fxml/customer.fxml", title = "Customer Details") public class CustomerController { @FXML private TextField name; @FXML private TextField id; @FXML private TextField phonenumber; @FXML private TextField bringing; @FXML @ActionTrigger("notedetails") private Button notedetails; @FXML @BackAction private Button back; @FXML private Text noted; @Inject private Restaurant restaurant; @ActionMethod("notedetails") public void notedetails() { noted.setText("Your details have been noted!"); String customerName = name.getText(); String customerID = id.getText(); String customerPhoneNumber = phonenumber.getText(); int customerBringing = Integer.parseInt(bringing.getText()); Customer customer = new Customer(customerName, customerID, customerPhoneNumber, customerBringing); restaurant.addCustomer(customer); } }

当我运行Main课程时,我去了客户窗口,并在填写详细信息后,文本字段向右移动!我检查了我的代码,只是仔细检查,我告诉我的老师这个问题,但他找不到代码的任何问题。

When I run the Main class, I went to the customers window, and after filling in the details, the text fields moved to the right! I checked my code, and just to double-check, I told my teacher about the problem, but he could not find anything wrong with the code.

我很惊讶这里没有其他人问过这个问题,所以这可能是我做过的事情。如果我错过了我的代码中的某些内容,请帮我查一下,或者找到解决问题的方法。

I am surprised that no one else here asked about this problem, so it might be something I have done. Please help me find if I missed something in my code, or else find a way to fix it.

推荐答案

我想下面的部分代码的干扰在这里已经定义了后退按钮的对齐。 : -

I think below part of the code is interfering here where the alignment of the back button has been defined. :-

HBox GridPane.rowIndex="4" GridPane.columnIndex="1" alignment="BASELINE_RIGHT"> <Button text="Back" fx:id="back"

编译器可能也会为文本字段分配相同的对齐方式。

The compiler might be assigning the same alignment to the text fields also.

建议,将对齐分配给标签的每一行。下面只是一个例子: -

Suggestion , assign the alignment to each row of the label. Below is just an example :-

<TextField alignment="BASELINE_RIGHT" GridPane.rowIndex="0" GridPane.columnIndex="1" fx:id="name"/> <TextField alignment="BASELINE_RIGHT" GridPane.rowIndex="1" GridPane.columnIndex="1" fx:id="id"/> <TextField alignment="BASELINE_RIGHT"GridPane.rowIndex="2" GridPane.columnIndex="1" fx:id="phonenumber"/> <TextField alignment="BASELINE_RIGHT"GridPane.rowIndex="3" GridPane.columnIndex="1"fx:id="bringing"/>

更多推荐

FXML

本文发布于:2023-11-06 17:15:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564300.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:FXML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!