AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / user-3151927

Adalberto José Brasaca's questions

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

JavaFX - Atualizando ProgressBar na Criação de Nós

  • 9

Já vi muito código na plataforma sobre atualização do ProgressBar usando thread, mas tudo está relacionado a algum cálculo realizado ou atualização de alguma propriedade de controle. Não sei se é possível, mas o que preciso é que o ProgressBar mostre o progresso na criação de 225 (15 X 15) a 2500 (50 x 50) TextFields. Abaixo estão os arquivos e o .fxml. Quando incluí a parte do código do thread, a grade parou de aparecer. Agradeço desde já.

A aplicação

insira a descrição da imagem aqui

Aplicação de grade.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();
    }
}

Controle de grade.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);
            }
        });

    }
}

Grade.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;
    }

}

visualização-principal.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 respostas
  • 31 Views
Martin Hope
Adalberto J. Brasaca
Asked: 2024-12-01 23:29:28 +0800 CST

JavaFX - IntelliJ não reconhece o controle da biblioteca ControlsFX

  • 7

Estou tentando usar o controle MaskerPane da biblioteca ControlsFX. Eu instalei a biblioteca no Scene Builder, inseri o controle MaskerPane em um contêiner e está funcionando.

insira a descrição da imagem aqui

insira a descrição da imagem aqui

Entretanto, mesmo depois de importar a biblioteca, o IntelliJ não reconhece o controle.

insira a descrição da imagem aqui

Ele me pede para importá-lo via Maven, embora eu já tenha feito exatamente isso.

insira a descrição da imagem aqui

Agradeço antecipadamente.

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 respostas
  • 34 Views
Martin Hope
Adalberto José Brasaca
Asked: 2024-10-29 00:14:56 +0800 CST

JavaFX - Comportamento diferente de dois GridPane em hierarquia de componentes iguais

  • 7

Acredito que as propriedades são definidas igualmente em ambos. Na grade "correct.fxml", se eu adicionar 1 linha ou 1 coluna, a barra de rolagem do respectivo ScrollPane aparece. Na grade "wrong.fxml" isso não acontece e não consigo descobrir o porquê. Talvez eu não esteja vendo algo diferente entre eles. Obrigado por qualquer ajuda.

Correto.fxml

insira a descrição da imagem aqui

Errado.fxml

insira a descrição da imagem aqui

Correto.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>

Errado.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 respostas
  • 33 Views
Martin Hope
Adalberto José Brasaca
Asked: 2024-10-20 22:48:47 +0800 CST

Insira um objeto composto (GridPane com TextFields) no ScrolPane

  • 9

Tenho uma classe que constrói uma grade com um array de TextFields usando GridPane. Preciso inserir essa grade em um ScrollPane que só aceita Node no método setContent(). Então estendo essa classe do GridPane. A classe Grid é instanciada e definida no ScrollPane pelo método onMnuItemNewAction da classe MainViewController.java, mas a grade não é mostrada. Obrigado pela ajuda.

MainView.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>

Principal.java

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 (o método de chamada)

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) {

    }

}

Grade.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 respostas
  • 63 Views

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Reformatar números, inserindo separadores em posições fixas

    • 6 respostas
  • Marko Smith

    Por que os conceitos do C++20 causam erros de restrição cíclica, enquanto o SFINAE antigo não?

    • 2 respostas
  • Marko Smith

    Problema com extensão desinstalada automaticamente do VScode (tema Material)

    • 2 respostas
  • Marko Smith

    Vue 3: Erro na criação "Identificador esperado, mas encontrado 'import'" [duplicado]

    • 1 respostas
  • Marko Smith

    Qual é o propósito de `enum class` com um tipo subjacente especificado, mas sem enumeradores?

    • 1 respostas
  • Marko Smith

    Como faço para corrigir um erro MODULE_NOT_FOUND para um módulo que não importei manualmente?

    • 6 respostas
  • Marko Smith

    `(expression, lvalue) = rvalue` é uma atribuição válida em C ou C++? Por que alguns compiladores aceitam/rejeitam isso?

    • 3 respostas
  • Marko Smith

    Um programa vazio que não faz nada em C++ precisa de um heap de 204 KB, mas não em C

    • 1 respostas
  • Marko Smith

    PowerBI atualmente quebrado com BigQuery: problema de driver Simba com atualização do Windows

    • 2 respostas
  • Marko Smith

    AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos

    • 1 respostas
  • Martin Hope
    Fantastic Mr Fox Somente o tipo copiável não é aceito na implementação std::vector do MSVC 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant Encontre o próximo dia da semana usando o cronógrafo 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor O inicializador de membro do construtor pode incluir a inicialização de outro membro? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský Por que os conceitos do C++20 causam erros de restrição cíclica, enquanto o SFINAE antigo não? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul O C++20 mudou para permitir a conversão de `type(&)[N]` de matriz de limites conhecidos para `type(&)[]` de matriz de limites desconhecidos? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann Como/por que {2,3,10} e {x,3,10} com x=2 são ordenados de forma diferente? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller O ponto e vírgula agora é opcional em condicionais bash com [[ .. ]] na versão 5.2? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench Por que um traço duplo (--) faz com que esta cláusula MariaDB seja avaliada como verdadeira? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng Por que `dict(id=1, **{'id': 2})` às vezes gera `KeyError: 'id'` em vez de um TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob: MobileAds.initialize() - "java.lang.Integer não pode ser convertido em java.lang.String" para alguns dispositivos 2024-03-20 03:12:31 +0800 CST

Hot tag

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

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve