2014-03-12 37 views
2

我在javafx中創建了一個Label,其中包含大量文本。setWrapText(true)不適用於JavaFX中的標籤

Label l1 = new Label("\t\tC-Mark and Attendance Calculator is a simple " 
      + "software to find both the C-Mark and monthly attendance " 
      + "of students. Inorder to use the features of this software," 
      + " user has to create an account for him first. Then he should " 
      + "login using the username and password. He will be able to " 
      + "perform all the operations then. Further details are mentioned" 
      + " in the 'HELP' section in the user home page."); 
l1.setWrapText(true); 
l1.setTextAlignment(TextAlignment.JUSTIFY); 

在此代碼中setWrapText(true)不起作用。爲什麼?我怎樣才能使它工作?

+0

你是如何確定一個沒有工作? –

+1

@UlukBiy因爲我的標籤內容顯示在一行中。我不知道爲什麼會這樣。你能提出一個解決方案嗎? – TomJ

+2

設置標籤的首選寬度。或者將標籤放入調整其子項的窗格中,例如HBox。 –

回答

9
Label l1 = new Label("\t\tC-Mark and Attendance Calculator is a simple " 
       + "software to find both the C-Mark and monthly attendance " 
       + "of students. Inorder to use the features of this software," 
       + " user has to create an account for him first. Then he should " 
       + "login using the username and password. He will be able to " 
       + "perform all the operations then. Further details are mentioned" 
       + " in the 'HELP' section in the user home page."); 
     l1.setWrapText(true); 
     l1.setTextAlignment(TextAlignment.JUSTIFY); 

這裏是一個SSCCE:

import javafx.application.Application; 
import javafx.geometry.Insets; 
import javafx.scene.Scene; 
import javafx.scene.control.Label; 
import javafx.scene.layout.StackPane; 
import javafx.scene.text.TextAlignment; 
import javafx.stage.Stage; 

public class WrappedLabelExample extends Application { 

    @Override 
    public void start(Stage primaryStage) { 
     Label l1 = new Label("\t\tC-Mark and Attendance Calculator is a simple " 
       + "software to find both the C-Mark and monthly attendance " 
       + "of students. Inorder to use the features of this software," 
       + " user has to create an account for him first. Then he should " 
       + "login using the username and password. He will be able to " 
       + "perform all the operations then. Further details are mentioned" 
       + " in the 'HELP' section in the user home page."); 
     l1.setWrapText(true); 
     l1.setTextAlignment(TextAlignment.JUSTIFY); 

     StackPane root = new StackPane(l1); 
     root.setPadding(new Insets(10)); 
     Scene scene = new Scene(root, 400, 400); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

    public static void main(String[] args) { 
     launch(args); 
    } 
} 

導致

enter image description here

+0

謝謝。這很有幫助... – TomJ

+2

@James_D,你能解釋一下這個問題可以解決的問題嗎?當它與問題相關的發佈代碼比較時,你的應答代碼有什麼不同?謝謝。 – Channa

+0

這篇文章有什麼意義?你剛剛複製了這個問題嗎? – tareq

相關問題