TabPane에 3 개의 탭이 있는데, 각각 다른 텍스트와 다른 길이의 텍스트 영역이 있습니다. 각 탭의 길이에 따라 텍스트 영역의 크기를 자동 조정하고 싶습니다. 어떻게해야하는지 이해가 안 되나요? 씬 빌더를 사용하고 계십니까? css? javaFX 메소드? 미리 감사드립니다 ...
텍스트 영역이 표시되는 텍스트에 따라 확대 또는 축소되도록 요청하는 것 같습니다.
그렇다면이 코드가 도움이되는지 확인하십시오.
import java.util.concurrent.Callable;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class AutosizingTextArea extends Application {
@Override
public void start(Stage primaryStage) {
TextArea textArea = new TextArea();
textArea.setMinHeight(24);
textArea.setWrapText(true);
VBox root = new VBox(textArea);
Scene scene = new Scene(root, 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
// This code can only be executed after the window is shown:
// Perform a lookup for an element with a css class of "text"
// This will give the Node that actually renders the text inside the
// TextArea
Node text = textArea.lookup(".text");
// Bind the preferred height of the text area to the actual height of the text
// This will make the text area the height of the text, plus some padding
// of 20 pixels, as long as that height is between the text area's minHeight
// and maxHeight. The minHeight we set to 24 pixels, the max height will be
// the height of its parent (usually).
textArea.prefHeightProperty().bind(Bindings.createDoubleBinding(new Callable<Double>(){
@Override
public Double call() throws Exception {
return text.getBoundsInLocal().getHeight();
}
}, text.boundsInLocalProperty()).add(20));
}
public static void main(String[] args) {
launch(args);
}
}
이것을 재사용 가능하게 만들고 싶다면 subclassing을 고려할 수 TextArea
있습니다. (일반적으로 컨트롤 클래스의 서브 클래 싱을 싫어합니다.) 여기서 까다로운 부분 TextArea
은 라이브 장면 그래프에 추가 된 후에 확장 을 만드는 코드를 실행하는 것 입니다 (조회가 작동하는 데 필요함). 이를 수행하는 한 가지 방법 (조금 해킹, imho)은을 사용 AnimationTimer
하여 조회를 수행하는 것입니다. 조회가 성공하면 중지 할 수 있습니다. 나는 이것을 여기에서 조롱했다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다