2014-12-30 5 views
0

제목에서 알 수 있듯이 javafx.scene.control.Label의 텍스트를 변경하면 동일한 레이아웃에 포함 된 모든 구성 요소의 크기가 조정됩니다. 이걸 정확히 어떻게 막을 수 있습니까?Labeled 컨트롤의 텍스트가 변경되었을 때 Labeled 컨트롤의 크기를 조정하지 못하게하려면 어떻게해야합니까?

<?xml version="1.0" encoding="UTF-8"?> 
<?language javascript?> 

<?import org.think.software.test.javafx.view.login.LoginView?> 

<?import javafx.scene.layout.GridPane?> 

<?import javafx.scene.control.Button?> 
<?import javafx.scene.control.Label?> 
<?import javafx.scene.control.TextField?> 
<?import javafx.scene.control.PasswordField?> 

<?import javafx.geometry.Insets?> 

<LoginView fx:controller="org.think.software.test.javafx.view.login.LoginView" 
    xmlns:fx="http://think.org/software/test/javafx/login" alignment="CENTER" 
    hgap="10" vgap="10"> 
    <padding> 
     <Insets top="35" right="35" bottom="35" left="35" /> 
    </padding> 
    <Label fx:id="infoLabel" GridPane.columnIndex="0" 
     GridPane.rowIndex="0" GridPane.columnSpan="3" text="%infoLabelText" /> 
    <Label fx:id="usernameLabel" GridPane.columnIndex="0" 
     GridPane.rowIndex="1" text="%usernameLabelText" /> 
    <TextField fx:id="usernameField" GridPane.columnIndex="1" 
     GridPane.rowIndex="1" GridPane.columnSpan="2" promptText="%usernameFieldPromptText" /> 
    <Label GridPane.columnIndex="0" GridPane.rowIndex="2" 
     text="%passwordLabelText" /> 
    <PasswordField fx:id="passwordField" 
     GridPane.columnIndex="1" GridPane.rowIndex="2" GridPane.columnSpan="2" 
     promptText="%passwordFieldPromptText" /> 
    <Button fx:id="loginButton" GridPane.columnIndex="0" 
     GridPane.rowIndex="3" GridPane.columnSpan="3" 
     onAction="java.lang.System.out.println(infoLabel.setText('Logging in...'));" 
     text="%loginButtonText" /> 
</LoginView> 

before text change

after text change

+0

@ Gemtastic, 오라클에서 제공 한 참조 가이드에서 FXML을 배웠습니다. 테스트 목적으로 onAction 속성을 정의했습니다. –

+0

@Gemtastic 실제로 LoginView는 내가 정의한 클래스입니다. 그것은 내가 정의한 다른 클래스 인 View를 확장합니다. 따라서 View는 GridPane을 확장합니다. 그 이유는 응용 프로그램의 모든 레이아웃에 컨트롤 "확대/축소"시스템을 공유하기를 원하기 때문에 코드 재 작성을 방지하기 위해서입니다. 이것이 의미가있는 경우 ... View/LoginView를 표시하는 코드가 실제로 없습니다. View는 GridPane을 확장하고 LoginView는 컨트롤러/발표자입니다. –

+0

@Gemtastic Nope, 코드 예제를 제공 하시겠습니까? –

답변

0

사용하는 일부 열 제약은 다른 열 확장을 제어하기 : 여기 내 FXML 마크 업입니다.

어떤 행에 두 개 이상의 구성 요소가 없기 때문에 텍스트 필드가 두 개의 열에 걸쳐있는 이유는 분명하지 않습니다. 내가 좋아하는 뭔가를 시도 할 것입니다 :

<?xml version="1.0" encoding="UTF-8"?> 
<?language javascript?> 

<?import org.think.software.test.javafx.view.login.LoginView?> 

<?import javafx.scene.layout.GridPane?> 
<?import javafx.scene.layout.ColumnConstraints?> 

<?import javafx.scene.control.Button?> 
<?import javafx.scene.control.Label?> 
<?import javafx.scene.control.TextField?> 
<?import javafx.scene.control.PasswordField?> 

<?import javafx.geometry.Insets?> 

<LoginView fx:controller="org.think.software.test.javafx.view.login.LoginView" 
    xmlns:fx="http://think.org/software/test/javafx/login" alignment="CENTER" 
    hgap="10" vgap="10"> 
    <padding> 
     <Insets top="35" right="35" bottom="35" left="35" /> 
    </padding> 
    <Label fx:id="infoLabel" GridPane.columnIndex="0" 
     GridPane.rowIndex="0" GridPane.columnSpan="2" text="%infoLabelText" /> 
    <Label fx:id="usernameLabel" GridPane.columnIndex="0" 
     GridPane.rowIndex="1" text="%usernameLabelText" /> 
    <TextField fx:id="usernameField" GridPane.columnIndex="1" 
     GridPane.rowIndex="1" promptText="%usernameFieldPromptText" /> 
    <Label GridPane.columnIndex="0" GridPane.rowIndex="2" 
     text="%passwordLabelText" /> 
    <PasswordField fx:id="passwordField" 
     GridPane.columnIndex="1" GridPane.rowIndex="2" 
     promptText="%passwordFieldPromptText" /> 
    <Button fx:id="loginButton" GridPane.columnIndex="0" 
     GridPane.rowIndex="3" GridPane.columnSpan="2" 
     onAction="java.lang.System.out.println(infoLabel.setText('Logging in...'));" 
     text="%loginButtonText" /> 

    <columnConstraints> 
     <!-- left column --> 
     <ColumnConstraints hgrow="NEVER" halignment="RIGHT" /> 
     <!-- right column --> 
     <ColumnConstraints hgrow="SOMETIMES" halignment="LEFT" minWidth="150" maxWidth="600" /> 
    </columnConstraints> 
</LoginView> 

minWidthmaxWidth의 값은 단지 예를; 당신은 그것들을 가지고 실험 할 수 있습니다 (아니면 그것들을 완전히 생략 할 수도 있습니다). 원하는 정확한 동작에 따라 오른쪽 열에 hgrow="ALWAYS"을 시도 할 수도 있습니다.