AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-3151927

Adalberto José Brasaca's questions

Martin Hope
Adalberto J. Brasaca
Asked: 2024-12-03 04:58:15 +0800 CST

JavaFX - 在节点创建时更新进度条

  • 9

我在平台上看到了很多关于使用线程更新 ProgressBar 的代码,但所有这些都与执行某些计算或更新某些控件属性有关。我不知道这是否可行,但我需要的是 ProgressBar 显示创建 225 (15 X 15) 到 2500 (50 x 50) 个 TextField 的进度。以下是文件和 .fxml。当我包含线程代码部分时,网格停止出现。提前谢谢您。

应用程序

在此处输入图片描述

网格应用程序.java

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class GridCenterApplication extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(GridCenterApplication.class.getResource("main-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load());
        stage.setTitle("Grid");
        stage.setScene(scene);
        stage.setMaximized(true);
        stage.show();
    }

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

网格控制器.java

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;

import java.net.URL;
import java.util.ResourceBundle;

public class GridCenterController implements Initializable {

    @FXML
    private ScrollPane scpGrid;

    @FXML
    private Spinner<Integer> spnCols;

    @FXML
    private Spinner<Integer> spnRows;

    @FXML
    private ProgressBar pgbProgress;

    GridPane gridPane;

    private final int CELL_HORIZONTAL_GAP = 1;
    private final int CELL_VERTICAL_GAP = 1;
    private final int CELL_HORIZONTAL_SIZE = 40;
    private final int CELL_VERTICAL_SIZE = 40;

    private int totalCols = 0;
    private int totalRows = 0;

    @FXML
    void onMnuItemNewGridAction(ActionEvent event) {

        if(!(scpGrid.getContent() == null)){
            scpGrid.setContent(null);
        }

        totalCols = spnCols.getValue();
        totalRows = spnRows.getValue();

        var newGrid = new Grid(totalCols, totalRows, CELL_HORIZONTAL_GAP, CELL_VERTICAL_GAP, CELL_HORIZONTAL_SIZE,
                CELL_VERTICAL_SIZE, pgbProgress);
        gridPane = newGrid.getGrid();
        scpGrid.setContent(gridPane);
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        SpinnerValueFactory<Integer> numberOfCols = new SpinnerValueFactory.IntegerSpinnerValueFactory(15, 50);
        SpinnerValueFactory<Integer> numberOfRows = new SpinnerValueFactory.IntegerSpinnerValueFactory(15, 50);
        spnCols.setValueFactory(numberOfCols);
        spnRows.setValueFactory(numberOfRows);
        scpGrid.contentProperty().addListener((observableValue, oldValue, newValue) -> {
            if (newValue != null && newValue.isVisible()) {
               pgbProgress.setProgress(0);
            }
        });

    }
}

网格.java

import javafx.concurrent.Task;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;

public class Grid {

    private final GridPane grid;

    public Grid(int totalCols, int totalRows, int CELL_HORIZONTAL_GAP, int CELL_VERTICAL_GAP, int CELL_HORIZONTAL_SIZE,
                int CELL_VERTICAL_SIZE, ProgressBar pgbProgress) {

        grid = new GridPane();
        grid.setHgap(CELL_HORIZONTAL_GAP);
        grid.setVgap(CELL_VERTICAL_GAP);
        TextField[][] arrayLetterField = new TextField[totalCols][totalRows];

        Task<Void> task = new Task<Void>() {
            @Override
            protected Void call() throws Exception {

                pgbProgress.setProgress(0);
                double total = totalCols * totalRows;
                double i = 1.0;

                for (int row = 0; row < totalRows; row++) {
                    for (int col = 0; col < totalCols; col++) {
                        arrayLetterField[col][row] = new TextField();
                        arrayLetterField[col][row].setMinSize(CELL_HORIZONTAL_SIZE, CELL_VERTICAL_SIZE);
                        arrayLetterField[col][row].setMaxSize(CELL_HORIZONTAL_SIZE, CELL_VERTICAL_SIZE );
                        grid.add(arrayLetterField[col][row], col, row);
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }

                        updateProgress(i, total);
                        i++;
                    }
                }
                return null;
            }
        };

        pgbProgress.progressProperty().bind(task.progressProperty());
        new Thread(task).start();

    }

    public GridPane getGrid() {
        return grid;
    }

}

主视图.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>

<BorderPane prefHeight="767.0" prefWidth="1053.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.gridpanetest.GridCenterController">
    <top>
        <VBox prefWidth="100.0" BorderPane.alignment="CENTER">
            <children>
                <MenuBar fx:id="mnuBar" prefHeight="25.0" prefWidth="360.0">
                    <menus>
                        <Menu mnemonicParsing="false" text="Grid">
                            <items>
                                <MenuItem mnemonicParsing="false" onAction="#onMnuItemNewGridAction" text="New grid" />
                            </items>
                        </Menu>
                    </menus>
                </MenuBar>
            <Pane prefHeight="80.0" prefWidth="1053.0">
               <children>
                  <Label layoutX="26.0" layoutY="15.0" text="Columns" />
                  <Label layoutX="26.0" layoutY="46.0" text="Rows" />
                  <Spinner fx:id="spnCols" layoutX="79.0" layoutY="11.0" prefHeight="25.0" prefWidth="57.0" />
                  <Spinner fx:id="spnRows" layoutX="79.0" layoutY="42.0" prefHeight="25.0" prefWidth="57.0" />
                  <ProgressBar fx:id="pgbProgress" focusTraversable="false" layoutX="185.0" layoutY="31.0" prefWidth="200.0" progress="0.0" />
               </children>
            </Pane>
            </children>
        </VBox>
    </top>
   <center>
        <ScrollPane fx:id="scpGrid" style="-fx-background-color: #dbbb92; -fx-background: #dbbb92;" BorderPane.alignment="CENTER" />
   </center>
</BorderPane>
multithreading
  • 1 个回答
  • 31 Views
Martin Hope
Adalberto J. Brasaca
Asked: 2024-12-01 23:29:28 +0800 CST

JavaFX - IntelliJ 无法识别 ControlsFX 库控件

  • 7

我正在尝试使用 ControlsFX 库中的 MaskerPane 控件。我在 Scene Builder 中安装了该库,将 MaskerPane 控件插入容器中,它就可以正常工作了。

在此处输入图片描述

在此处输入图片描述

但是,即使导入库后,IntelliJ 也无法识别该控件。

在此处输入图片描述

它要求我通过 Maven 导入它,尽管我已经这样做了。

在此处输入图片描述

先感谢您。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>PaneTeste</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>PaneTeste</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.9.2</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>17.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>17.0.6</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>11.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.controlsfx</groupId>
            <artifactId>controlsfx</artifactId>
            <version>11.1.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running with: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>com.example.paneteste/com.example.gridpanetest.GridCenterApplication</mainClass>
                            <launcher>app</launcher>
                            <jlinkZipName>app</jlinkZipName>
                            <jlinkImageName>app</jlinkImageName>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <noHeaderFiles>true</noHeaderFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
intellij-idea
  • 1 个回答
  • 34 Views
Martin Hope
Adalberto José Brasaca
Asked: 2024-10-29 00:14:56 +0800 CST

JavaFX - 相同组件层次结构中两个 GridPane 的不同行为

  • 7

我认为这两个属性的定义是相同的。在“correct.fxml”网格中,如果我添加 1 行或 1 列,则会出现相应的 ScrollPane 滚动条。在“wrong.fxml”网格中不会发生这种情况,我不明白为什么。也许我没有看到它们之间的区别。感谢您的帮助。

正确.fxml

在此处输入图片描述

错误.fxml

在此处输入图片描述

正确.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="429.0" 
prefWidth="761.0" stylesheets="@stylesheet.css" xmlns="http://javafx.com/javafx/22" 
xmlns:fx="http://javafx.com/fxml/1">
   <center>
      <ScrollPane BorderPane.alignment="CENTER">
         <content>
            <StackPane>
               <children>
                  <Pane StackPane.alignment="CENTER">
                     <children>
                        <GridPane alignment="CENTER" hgap="1.0" vgap="1.0">
                          <columnConstraints>
                            <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                            <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                             <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="100.0" />
                          </columnConstraints>
                          <rowConstraints>
                            <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                          </rowConstraints>
                        </GridPane>
                     </children>
                  </Pane>
               </children>
            </StackPane>
         </content>
      </ScrollPane>
   </center>
</BorderPane>

错误.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>

<BorderPane prefHeight="277.0" prefWidth="495.0" xmlns="http://javafx.com/javafx/22" 
xmlns:fx="http://javafx.com/fxml/1" 
fx:controller="br.com.ablogic.crossword.MainViewController">
   <center>
      <ScrollPane fx:id="scpGrid" fitToHeight="true" fitToWidth="true" 
focusTraversable="false" BorderPane.alignment="CENTER">
         <content>
            <StackPane fx:id="stkPane">
               <children>
                  <Pane fx:id="pane" StackPane.alignment="CENTER">
                     <children>
                        <GridPane alignment="CENTER" hgap="1.0" vgap="1.0">
                          <columnConstraints>
                            <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                              <ColumnConstraints halignment="CENTER" hgrow="NEVER" 
maxWidth="40.0" minWidth="40.0" prefWidth="40.0" />
                          </columnConstraints>
                          <rowConstraints>
                            <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                            <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                            <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                              <RowConstraints maxHeight="40.0" minHeight="40.0" 
prefHeight="40.0" valignment="CENTER" vgrow="NEVER" />
                          </rowConstraints>
                        </GridPane>
                     </children>
                 </Pane>
              </children>
           </StackPane>
        </content>
     </ScrollPane>
  </center>
</BorderPane>
javafx
  • 1 个回答
  • 33 Views
Martin Hope
Adalberto José Brasaca
Asked: 2024-10-20 22:48:47 +0800 CST

将复合对象(带有 TextFields 的 GridPane)插入到 ScrolPane 中

  • 9

我有一个使用 GridPane 构建带有 TextFields 数组的网格的类。我需要将此网格插入到只接受 setContent() 方法中的 Node 的 ScrollPane 中。因此我从 GridPane 扩展了此类。Grid 类由 MainViewController.java 类的 onMnuItemNewAction 方法在 ScrollPane 中实例化和设置,但网格未显示。感谢您的帮助。

主视图.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>

<BorderPane prefHeight="277.0" prefWidth="495.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" 
fx:controller="br.com.ablogic.crossword.MainViewController">
    <top>
       <VBox prefWidth="100.0" BorderPane.alignment="CENTER">
         <children>
            <MenuBar fx:id="mnuBar" prefHeight="25.0" prefWidth="360.0">
              <menus>
                <Menu mnemonicParsing="false" text="File">
                  <items>
                    <MenuItem fx:id="mnuItemNew" mnemonicParsing="false" onAction="#onMnuItemNewAction" text="New grid" />
                  </items>
                </Menu>
              </menus>
            </MenuBar>
         </children>
      </VBox>
   </top>
   <center>
      <ScrollPane fx:id="scpGrid" fitToHeight="true" fitToWidth="true" pannable="true" style="-fx-background-color: #dbbb92; -fx-background: #dbbb92;" BorderPane.alignment="CENTER" />
   </center>
</BorderPane>

主程序

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;

public class Main extends Application {
    @Override
    public void start(Stage stage) throws IOException {

        FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("MainView.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 800, 600);
        stage.setTitle("Grid Demo");
        stage.setScene(scene);
        stage.show();
    }

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

}

MainViewController.java(调用方法)

import javafx.geometry.Pos;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ScrollPane;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import java.net.URL;
import java.util.ResourceBundle;

public class MainViewController implements Initializable {

    @FXML
    private MenuItem mnuItemNew;

    @FXML
    private ScrollPane scpGrid;

    @FXML
    public void onMnuItemNewAction() {
        int cols = 10;
        int rows = 10;
        int horizontalGap = 1;
        int verticalGap = 1;
        int fieldHorizontalSize = 40;
        int fieldVerticalSize = 40;
        var newGrid = new Grid(cols, rows, horizontalGap, verticalGap, fieldHorizontalSize, fieldVerticalSize);
        scpGrid.setContent(newGrid);
        newGrid.setAlignment(Pos.CENTER);
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {

    }

}

网格.java

import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import java.net.URL;
import java.util.ResourceBundle;

public class Grid extends GridPane implements Initializable {
    private final int totalColumnFields;
    private final int totalRowFields;
    private final int horizontalGap;
    private final int verticalGap;
    private final int fieldHorizontalSize;
    private final int fieldVerticalSize;
        
    public Grid(int totalColumnFields, int totalRowFields, int horizontalGap, int verticalGap, int fieldHorizontalSize, int fieldVerticalSize) {
        this.totalColumnFields = totalColumnFields;
        this.totalRowFields = totalRowFields;
        this.horizontalGap = horizontalGap;
        this.verticalGap = verticalGap;
        this.fieldHorizontalSize = fieldHorizontalSize;
        this.fieldVerticalSize = fieldVerticalSize;
    }

    @Override
    public void initialize(URL url, ResourceBundle rb) {

        this.setHgap(horizontalGap);
        this.setVgap(verticalGap);
        TextField[][] arrayLetterField = new TextField[totalColumnFields][totalRowFields];

        for (int row = 0; row < totalRowFields; row++) {
            for (int col = 0; col < totalColumnFields; col++) {
                arrayLetterField[col][row] = new TextField();
                arrayLetterField[col][row].setMinSize(fieldHorizontalSize, fieldVerticalSize);
                arrayLetterField[col][row].setMaxSize(fieldHorizontalSize, fieldVerticalSize );
                this.add(arrayLetterField[col][row], col, row);
            }
        }            
    }    
}
java
  • 1 个回答
  • 63 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve