Javafx自动调整大小并将多边形重新定位到父窗格

时间:2018-12-09 10:37:44

标签: javafx resize polygon pane

对于一个正在制作的程序,我需要可视化多个多边形/矩形。我有以下fxml文件:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="FX.Controller">
   <children>
      <TitledPane animated="false" text="Poging 1" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <content>
            <SplitPane dividerPositions="0.25" prefHeight="200.0" prefWidth="200.0">
               <items>
                  <SplitPane dividerPositions="0.5" orientation="VERTICAL" prefHeight="200.0" prefWidth="160.0">
                    <items>
                      <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
                           <children>
                              <Label layoutX="54.0" layoutY="37.0" text="Algemene info" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
                           </children>
                        </AnchorPane>
                        <ScrollPane fx:id="restPieces_pane" prefHeight="200.0" prefWidth="200.0">
                          <content>
                            <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0" />
                          </content>
                        </ScrollPane>
                    </items>
                  </SplitPane>
                  <TabPane fx:id="piece_Tab" prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" />
               </items>
            </SplitPane>
         </content>
      </TitledPane>
   </children>
</AnchorPane>

在tabPane中,我为用户要可视化的每个“片段”(一组多边形)创建一个新的标签。我创建多边形并制作选项卡的代码:

//MY_Polygon and Piece_MYPolygon extend from java.awt.Polygon
//Polygon in this piece of code is javafx.scene.shape.Polygon

 public void showProblem() {
        for(Piece_MYPolygon pmyp : problem.getGrotefiguren()){
            //New figure => nieuwe tab
            Pane pane = new Pane();
            Polygon piece = new Polygon();
            List<Double> piece_coords = new ArrayList<>();
            for (int a=0; a<pmyp.npoints; a++){
                piece_coords.add((double) pmyp.xpoints[a]);
                piece_coords.add((double) pmyp.ypoints[a]);
            }
            piece.getPoints().addAll(piece_coords);
            piece.setFill(Color.GRAY);
            piece.autosize();
            pane.getChildren().add(piece);
            for(MYPolygon myp: pmyp.getVoids()){
                List<Double> coords = new ArrayList<>();
                for (int i=0; i<myp.npoints; i++){
                    coords.add((double) myp.xpoints[i]);
                    coords.add((double) myp.ypoints[i]);
                }
                Polygon p = new Polygon();
                p.getPoints().addAll(coords);
                p.setFill(Color.CYAN);
                p.autosize();
                pane.getChildren().add(p);
            }
            for(MYPolygon myp: pmyp.getForbidden_areas()){
                List<Double> coords = new ArrayList<>();
                for (int i=0; i<myp.npoints; i++){
                    coords.add((double) myp.xpoints[i]);
                    coords.add((double) myp.ypoints[i]);
                }
                Polygon p = new Polygon();
                p.getPoints().addAll(coords);
                p.setFill(Color.RED);
                p.autosize();
                pane.getChildren().add(p);
            }
            pane.autosize();

            Tab newTab = new Tab(pmyp.getEigenschappen().get("PartRef"),pane);
            piece_Tab.getTabs().add(newTab);
        }
    }

当我运行代码(并使应用全屏显示)时,它对应以下内容:

not properly sized image

这大约是我需要查看的数字的一半,并且在调整应用程序大小时,显示的多边形根本不会调整大小。我很乐意接受任何解决此问题的方法。谢谢!

0 个答案:

没有答案