2017-02-08 1 views
1

スクロールの場合はScrollPane、ビューの場合はVBoxを使用してチャットを作成しようとしています(scroll.setContent(vbox);)。各メッセージは新しいHBoxLabelを作成します。 ラベルに十分なスペースがその作業罰金をスクロールせずに存在している場合は、テキストが含まれているとtext.setWrapText(true);ScrollPane内のHBox内にJavaFXラベルがラップされていません

を宣言:

Wrapping work

しかしVHox高さ(ScrollPaneのビュー)、その後のメッセージの高さも大きく動作していないラップ:

Wrapping not working

EDIT:関連するコード:

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.Label; 
import javafx.scene.control.ScrollPane; 
import javafx.scene.layout.HBox; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 

public class ChatExample extends Application 
{ 
    public static void main(String[] args) 
    { 
     launch(args); 
    } 

    @Override 
    public void start(Stage stage) throws Exception 
    { 
     ScrollPane scroll = new ScrollPane(); 
     scroll.setFitToHeight(true); 
     scroll.setPrefSize(300, 300); 
     VBox chat = new VBox(); 
     chat.setSpacing(10); 
     scroll.setContent(chat); 

     chat.getChildren().add(addMessage("This is a wrapped message, This is a wrapped message")); 
     chat.getChildren().add(addMessage("This is a wrapped message, This is a wrapped message")); 
     chat.getChildren().add(addMessage("This is a wrapped message, This is a wrapped message")); 
     chat.getChildren().add(addMessage("This is a wrapped message, This is a wrapped message")); 

     final Scene scene = new Scene(scroll, 300, 300); 

     stage.setScene(scene); 
     stage.show(); 
    } 

    public HBox addMessage(String message) 
    { 
     HBox hbox = new HBox(); 
     Label label = new Label(message); 
     label.setWrapText(true); 
     label.setMaxWidth(50); 

     hbox.getChildren().add(label); 
     return hbox; 
    } 
} 
+1

それを削除し、[最小、コンプリート&検証可能例】(http://stackoverflow.com/help/mcve)(別名MCVE)を投稿してください。 – Itai

答えて

1

小さな例を書くことに@sillyflyのおかげで、私はどのような場合、このような状況を考え出しました。

scroll.setFitToHeight(true);は、この問題を作ったので、私は

関連する問題