17

TextArea親ペインの全幅と高さを取るにはどうすればよいですか。

私はこれを試しました:

TextArea textArea = new TextArea();
textArea.setScaleX( 100 );
textArea.setScaleY( 100 );

しかし、上部のビアで定義された要素parent.setTop(...)は覆われていました。
を減らしscaleYても効果はありませんでした。

これを達成するために他に何をしなければなりませんか?

ありがとう

4

5 に答える 5

30

MAX_VALUE ソリューションは少しハックであり、パフォーマンスの問題を引き起こす可能性があります。また、これに対する答えは、親コンテナーが何であるかによって異なります。とにかく、それを行うより良い方法は次のようになります。

textArea.prefWidthProperty().bind(<parentControl>.prefWidthProperty());
textArea.prefHeightProperty().bind(<parentConrol>.prefHeightProperty());

特に親が明示的なものではなく計算された次元を使用している場合は、優先プロパティを実際のプロパティにバインドすることもできます。

textArea.prefWidthProperty().bind(<parentControl>.widthProperty());
textArea.prefHeightProperty().bind(<parentConrol>.heightProperty());

親コンテナの layoutChildren() メソッドをオーバーライドして呼び出すことにより、バインディングを使用せずにこれを行うこともできます。

textArea.resize(getWidth(), getHeight());

super.layoutChildren() を呼び出すことを忘れないでください...

于 2011-07-07T20:09:27.250 に答える
16

これで解決

textArea.setPrefSize( Double.MAX_VALUE, Double.MAX_VALUE );
于 2011-05-30T15:54:10.120 に答える
5

これは、をに配置することで実現できTextAreaますBorderPane

Stage stage = new Stage();
stage.setTitle("Resizing TextArea");

final BorderPane border = new BorderPane();
Scene scene = new Scene(border);

TextArea textArea = new TextArea();
textArea.setStyle("-fx-background-color: #aabbcc;");

border.setCenter(textArea);

primaryStage.setScene(scene);
primaryStage.setVisible(true);

HBoxまたはの中に配置することもできますVBox。その場合、サイズ変更は水平/垂直方向に制限されます。これが問題かどうかわからない。

于 2011-08-01T17:45:25.753 に答える
-2
<TextArea style="-fx-pref-height: 10px;"/>
于 2016-11-29T15:33:44.737 に答える
-4

あなたはcssファイルを作成することでそれを行うことができます。

textarea
{
width://your width
} 
于 2011-05-30T18:21:28.007 に答える