내 GUI 애플리케이션의 윈도우 중 하나는 내부에서 동일한 컨트롤이있는 유사한 HBox로 구성됩니다. 모든 것을 맨 위층 창 (이 경우 앵커 창)에 가운데에 배치하고 싶습니다.CSS에서 JavaFX 앵커 패널의 앵커 설정
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Button?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
<VBox fx:id="modeWindowPane" alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Current" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</children>
</HBox>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Frequency" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</children>
</HBox>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Fade In" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</children>
</HBox>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Fade Out" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</children>
</HBox>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Offset" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</children>
</HBox>
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Label contentDisplay="CENTER" maxHeight="1.7976931348623157E308" prefWidth="100.0" text="Stimulation Time" />
<TextField prefWidth="100.0" />
<Button maxHeight="1.7976931348623157E308" mnemonicParsing="false" text="Set Current"/>
</HBox>
</VBox>
</AnchorPane>
당신은 그 모든 HBox의에서 왼쪽/오른쪽/위/아래 앵커가 볼 수
여기에 코드입니다. 어떻게 든 그들을 매개 변수화하기를 원했고 CSS를 통해 FXML 파일의 기본 HBox 속성을 설정했습니다. 그러나 내가 더 많은 정보 (튜토리얼, 오라클 레퍼런스, 스택)를 찾기 시작했을 때 나는 아무것도 유용하지 못했다.
예를 들어 원하는 방식으로 모든 구성 요소를 편집 할 필요가없는 방법이 있는지 누군가가 알 수 있습니까? 또한 MVC 디자인 패턴을 준수해야합니다.
'HBox'는 부모로'VBox'를 가지고 있습니다 : 그것들에'AnchorPane' 속성을 설정하는 것은 의미가 없습니다. –
@James_D, FXML에서 앵커 창에 상자가 있으면 해당 속성을 앵커 창에 추가 할 수 있습니다. 그들은 직접 창 속성보다 정렬 설정입니다. – notmyf4ulty
그러나 그들은 'AnchorPane'에 (직접적으로) 있지 않습니다. 그들은'VBox'에 있습니다. –