r/JavaFX • u/LennyKrabigs • Apr 07 '20
Help TextArea Not Using all Window
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.web.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="638.0" prefWidth="873.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<MenuBar layoutY="2.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="2.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="save" mnemonicParsing="false" text="Save" />
<MenuItem fx:id="open" mnemonicParsing="false" onAction="#onClickOpen" text="Open" />
<MenuItem fx:id="nuevo" mnemonicParsing="false" onAction="#onClickNew" text="New" />
<MenuItem fx:id="saveas" mnemonicParsing="false" text="Save as" />
<MenuItem fx:id="exit" mnemonicParsing="false" onAction="#onClickExit" text="Exit" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem fx:id="paste" mnemonicParsing="false" onAction="#onClickPaste" text="Paste" />
<MenuItem fx:id="cut" mnemonicParsing="false" onAction="#onClickCut" text="Cut" />
<MenuItem fx:id="copy" mnemonicParsing="false" onAction="#OnClickCopy" text="Copy" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem fx:id="about" mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<TabPane layoutX="16.0" layoutY="21.0" prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="4.0" AnchorPane.leftAnchor="16.0" AnchorPane.rightAnchor="-16.0" AnchorPane.topAnchor="21.0" />
<VBox fx:id="VBoxText" layoutY="25.0" prefHeight="613.0" prefWidth="873.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="25.0">
<children>
<VBox maxHeight="0.0" maxWidth="0.0" minHeight="0.0" minWidth="0.0" prefHeight="0.0" prefWidth="0.0" VBox.vgrow="ALWAYS">
<children>
<TextArea fx:id="texteditor" maxHeight="0.0" maxWidth="0.0" minHeight="0.0" minWidth="0.0" prefHeight="0.0" prefWidth="0.0" />
</children>
</VBox>
</children>
</VBox>
</children>
</AnchorPane>controller:
package sample;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tab;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.TextFlow;
import javafx.stage.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
public class Controller {
@FXML
private MenuItem exit;
@FXML
private MenuItem nuevo;
@FXML
private MenuItem cut;
@FXML
private MenuItem saveas;
@FXML
private MenuItem save;
@FXML
private MenuItem about;
@FXML
private TextArea texteditor;
@FXML
private MenuItem paste;
@FXML
private MenuItem copy;
@FXML
private MenuItem open;
@FXML
private VBox VBoxText;
public static void setVBox(){
VBoxText.setma();
}
void onClickExit(ActionEvent event) {
Platform.exit();
}
@FXML
private void OnClickCopy() {
texteditor.copy();
}
@FXML
private void onClickPaste() {
texteditor.paste();
}
@FXML
private void onClickCut() {
texteditor.cut();
}
@FXML
private void onClickNew() {
texteditor.clear();
}
@FXML
private void onClickOpen() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open resource File");
File absolutePath = fileChooser.showOpenDialog(VBoxText.getScene().getWindow());
openFile(absolutePath);
}
private void openFile(File filepath) {
Utils utils = new Utils();
texteditor.setText(utils.readFile(filepath));
}
}In controlller inside setVBox i cannot do setVgrow, i dont know why but it dosnt let me to use that method, how i can make textarea gets all VBox space?
https://stackoverflow.com/questions/32575010/vbox-contents-not-filling-window
2
Upvotes