JavaFXでテキストノードの行間隔を調整するにはどうすればよいですか?
javafx.scene.textの行間隔プロパティ。textクラスは、テキスト(ノード)の行間の行間隔を垂直方向に指定します。
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 TextSpacing extends Application {
public void start(Stage stage) throws FileNotFoundException {
//Reading the contents of a text file.
InputStream inputStream = new FileInputStream("D:\\sample_text.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.JUSTIFY);
//Setting the space
text.setLineSpacing(2.0);
//Setting the stage
Group root = new Group(text);
Scene scene = new Scene(root, 595, 150, Color.BEIGE);
stage.setTitle("Line Spacing (2.0)");
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.
出力
同様に、行間隔を8.0 −
-
JavaFXスライダーを作成するにはどうすればよいですか?
JavaFXは、Sliderと呼ばれるクラスを提供します。これは、値の連続範囲を表示するスライダーコンポーネントを表します。これには、数値が表示されるトラックが含まれています。トラックに沿って、数字を指す親指があります。スライダーの最大値、最小値、初期値を指定できます。 スライダーを作成するには、Sliderクラスをインスタンス化し、必要なプロパティを設定して、シーンに追加する必要があります。 例 import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scen
-
Tkinterでテキストウィジェットの現在の行を強調表示するにはどうすればよいですか?
Tkinterのテキストを使用できます 複数行のユーザー入力を受け入れるウィジェット。テキストを挿入したり、情報を表示したり、テキストウィジェットから出力を取得したりできます。 テキストウィジェットで現在選択されているテキストを強調表示するには、 tag_add()を使用できます。 現在のテキストにのみタグを追加するメソッド。 例 # Import the required library from tkinter import * # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry