javaFX를 사용하여 대화 상자를 만들려고합니다. 현재 페이지가 가득 차면 내 페이지를 자동 스크롤하려고합니다. 하지만 제대로 작동하지 않습니다. 내가 그것을 실행하면javaFX의 자동 스크롤
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;
public class ChatBox extends Application{
final ScrollPane sp = new ScrollPane();
public static void main(String[] args){
launch(args);
}
public void start(Stage stage){
TextFlow textFlow = new TextFlow();
textFlow.setPadding(new Insets(10));
textFlow.setLineSpacing(10);
textFlow.setPrefSize(300,300);
TextField textField = new TextField();
textField.setPrefSize(50,30);
Button button = new Button("Send");
button.setPrefSize(80,30);
VBox container = new VBox();
VBox box = new VBox();
box.getChildren().addAll(sp,textFlow);
container.setPadding(new Insets(10));
container.getChildren().addAll(box, new HBox(textField, button));
VBox.setVgrow(sp, Priority.ALWAYS);
VBox.setVgrow(textFlow, Priority.ALWAYS);
textField.prefWidthProperty().bind(container.widthProperty().subtract(button.prefWidthProperty()));
// On Enter press
textField.setOnKeyPressed(e -> {
if(e.getCode() == KeyCode.ENTER) {
button.fire();
}
});
button.setOnAction(e -> {
Text text;
if(textFlow.getChildren().size()==0){
text = new Text(textField.getText());
} else {
// Add new line if not the first child
text = new Text("\n" + textField.getText());
}
textFlow.getChildren().add(text);
textField.clear();
textField.requestFocus();
});
VBox vb = new VBox();
vb.getChildren().addAll(textFlow);
sp.setVmax(440);
sp.setPrefSize(400, 300);
sp.setContent(vb);
sp.vvalueProperty().bind((ObservableValue<? extends Number>) vb.heightProperty());
//sp.setPannable(true);
Scene scene = new Scene(container, 400, 300);
stage.setScene(scene);
stage.setTitle("ChatBox");
stage.show();
}
}
는 페이지가 아래로 여기
는 첫 번째 메시지와 스크롤 바가 위치가 상단에 있어야하지만 아래 가리키는 이었지만까지 하이 간다 간다 . 어떻게해야합니까?
감사합니다 :)하지만 스크롤 할 때 아래로 현재 메시지를 제대로 표시해야하지만 그것의 절반을 보여줍니다 그리고 나는 그것을 제대로 볼 수 아래로 스크롤해야합니다. 그것을 해결할 방법이 있습니까? – IAmBlake
@IAmBlake : 레이아웃 문제가 다시 발생하여 textFlow.setPadding (새 Insets (10))에 주석을 달아보십시오. 나에게 도움이 됐어. 네가 할 수 있으면 받아 들일 수있는 대답을 업데이트 했어. 문제가 있으면 알려줘. – grsdev7