JavaFXでテキストの配置を調整するにはどうすればよいですか?
値をwrappingWidthに設定することで、ユーザースペースのテキストに固定幅を設定できます。 財産。そうすると、指定された幅がユーザー座標でのテキストの境界と見なされ、テキストは指定された幅で幅に配置されます。
このプロパティに値を指定していない場合、デフォルトでは、テキスト内の最長の行の長さがバウンディングボックスの幅と見なされます。
テキストの配置とは、バウンディングボックス内でテキストを水平方向に配置することです。 setTextAlignment()を使用して、テキストの配置を調整できます。 方法。このメソッドは、 TextAlignmentという名前の列挙型の定数の1つを受け入れます。 それに応じてテキストを調整します。この列挙型は3つの定数を提供します-
-
センター −テキストをバウンディングボックスの中央に揃えます。
-
正当化 −バウンディングボックス内のテキストの配置を揃えます。
-
左 −テキストを左揃えにします。
-
右 −テキストを右揃えにします。
例
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Scanner;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
public class TextAllignment extends Application {
public void start(Stage stage) throws FileNotFoundException {
//Reading the contents of a text file.
InputStream inputStream = new FileInputStream("D:\\sample.txt");
Scanner sc = new Scanner(inputStream);
StringBuffer sb = new StringBuffer();
while(sc.hasNext()) {
sb.append(" "+sc.nextLine()+"\n");
}
//Creating a text object
Text text = new Text(10.0, 25.0, sb.toString());
//Wrapping the text
text.setWrappingWidth(565);
//Setting the alignment
text.setTextAlignment(TextAlignment.Right);
//Setting the stage
Group root = new Group(text);
Scene scene = new Scene(root, 595, 150, Color.BEIGE);
stage.setTitle("Text Alignment");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
} sample.txt
sample.txtファイルの内容は次のとおりです-
Tutorials Point originated from the idea that there exists a class of readers who respond better to online content and prefer to learn new skills at their own pace from the comforts of their drawing rooms. The journey commenced with a single tutorial on HTML in 2006 and elated by the response it generated, we worked our way to adding fresh tutorials to our repository which now proudly flaunts a wealth of tutorials and allied articles on topics ranging from programming languages to web designing to academics and much more.
出力
同様に、アライメント値を変更すると、それに応じて-
として出力が得られます。左-
CENTER −
JUSTIFY −
-
Tkinterラベルのテキストを取得するにはどうすればよいですか?
Tkinterラベルは、ウィンドウにテキストまたは画像を作成して表示するために使用されます。フォントファミリー、パディング、幅、高さなどのラベル情報をカスタマイズするために使用できるいくつかのコンポーネントと関数があります。ウィンドウにラベルテキストを表示するために、必要なテキストの値を書き込むことができます。ウィンドウに表示されます。 例 #Import the required library from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the geometry of the
-
テキストの大文字と小文字を変更する方法
一部のユーザーから、Microsoft Word、Googleドキュメント、またはテキストエディタを使用せずに、小文字を大文字に(またはその逆に)変更する方法があるかどうかという質問が寄せられています。影響を受けた一部のユーザーは、誤って入力したテキストを間違った大文字で削除することも検討していますが、この問題を解決するためのはるかに効率的な方法があります。 幸い、Microsoft Wordおよびその他すべてのテキストエディタには、選択したテキストの大文字と小文字を変更する機能が含まれています。技術にまったく精通していなくても、すべて非常に簡単に実行できます。実際、これを行うにはさまざま