Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello everyone.
I'm making an application where I have a grid cell. in there i wanna place controls that fille the whole-cell width. i achieved this with a button but i cannot get it to work with my custom control. this is the code i usse for the sizing:
Java
Button b = new Button("delete");
b.setMaxWidth(Double.MAX_VALUE);
GridPane.setFillWidth(b, true);
gridPane.add(b,0,0);

WLAcordionControl w = new WLAcordionControl();
w.controller.Main.setMaxWidth(Double.MAX_VALUE);
GridPane.setFillWidth(w.controller.Main, true);
gridPane.add(w,0,1);

and this is the result i get link to image

here is the fxml code of my custom control:
XML
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Accordion?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane fx:id="Main" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <Accordion AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <panes>
          <TitledPane id="Container" fx:id="Container" animated="false" text="untitled 1">
            <content>
              <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                     <children>
                        <TextArea id="text" fx:id="text" layoutX="19.6" layoutY="19.6" prefHeight="354.0" prefWidth="787.0" AnchorPane.bottomAnchor="0.5" AnchorPane.leftAnchor="0.5" AnchorPane.rightAnchor="0.5" AnchorPane.topAnchor="10.0" />
                     </children>
                  </AnchorPane>
            </content>
          </TitledPane>
        </panes>
      </Accordion>
   </children>
</AnchorPane>


the code of my customcontrol's controller
Java
package ArticleControls.wlAcordion;

import ArticleControls.ArticleControl;
import javafx.fxml.FXML;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;

public class WLAcordionController extends ArticleControl {

    @FXML
    public AnchorPane Main;

    public WLAcordionController(){

    }

    @Override
    public Object GetData() {
        return null;
    }
}


and this is the code of the custom control itself:
Java
package ArticleControls.wlAcordion;

import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;

import java.io.IOException;

public class WLAcordionControl extends AnchorPane {

    public WLAcordionController controller;
    public WLAcordionControl(){

        super();

        try {
            FXMLLoader loader = new FXMLLoader(getClass().getResource("WlAcordion.fxml"));

            controller = new WLAcordionController();

            loader.setController(controller);

            Node n = loader.load();

            this.getChildren().add(n);


        }
        catch (IOException ix){

        }
    }
}


Thx for helping.

What I have tried:

I originally tried it with a vbox but that also did not work.
Posted
Updated 16-Feb-20 4:00am
v2

1 solution

ok i fixed it. was a stupid mistake from me.
the problem was that when i added my control i did this
gridPane.add(w,0,1);

but it needed to be
gridPane.add(w.controller.Main,0,1);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900