Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. package application;
  2.  
  3. import javafx.application.Application;
  4. import javafx.collections.FXCollections;
  5. import javafx.collections.ObservableList;
  6. import javafx.geometry.Pos;
  7. import javafx.scene.Scene;
  8. import javafx.scene.control.CheckBox;
  9. import javafx.scene.control.ComboBox;
  10. import javafx.scene.control.Label;
  11. import javafx.scene.layout.BorderPane;
  12. import javafx.scene.layout.HBox;
  13. import javafx.scene.text.Font;
  14. import javafx.scene.text.FontPosture;
  15. import javafx.scene.text.FontWeight;
  16. import javafx.stage.Stage;
  17.  
  18. public class TextStorlek extends Application {
  19.  
  20. @Override
  21. public void start(Stage primaryStage) {
  22.  
  23. int size = 0;
  24.  
  25. BorderPane root = new BorderPane();
  26.  
  27. Scene scene = new Scene(root, 500, 300);
  28.  
  29. primaryStage.setScene(scene);
  30.  
  31. primaryStage.show();
  32.  
  33. Label label = new Label("Font Name");
  34.  
  35. ComboBox<String> comboBox;
  36. ComboBox<Integer> comboBox1;
  37.  
  38. ObservableList<String> entries = FXCollections.observableArrayList(Font.getFamilies());
  39. comboBox = new ComboBox<>(entries);
  40.  
  41. Label label1 = new Label("Font Size");
  42.  
  43. ObservableList<Integer> entries1 = FXCollections.observableArrayList();
  44.  
  45. comboBox1 = new ComboBox<>(entries1);
  46.  
  47. for (int i = 4; i < 100 + 4; i += 4) {
  48.  
  49. comboBox1.getItems().addAll(i);
  50.  
  51. }
  52.  
  53. HBox hbox = new HBox(10);
  54. hbox.getChildren().addAll(label, comboBox, label1, comboBox1);
  55.  
  56. Label label2 = new Label("Programming is fun");
  57. HBox hbox1 = new HBox();
  58. hbox1.getChildren().addAll(label2);
  59.  
  60. CheckBox checkboxBold = new CheckBox("Bold");
  61. CheckBox checkboxItalic = new CheckBox("Italic");
  62.  
  63. HBox hbox2 = new HBox();
  64. hbox2.getChildren().addAll(checkboxBold, checkboxItalic);
  65.  
  66. hbox.setAlignment(Pos.TOP_CENTER);
  67. hbox1.setAlignment(Pos.CENTER);
  68. hbox2.setAlignment(Pos.BOTTOM_CENTER);
  69.  
  70. comboBox.setValue("Choose a font style");
  71. comboBox1.setValue(30);
  72.  
  73. root.setTop(hbox);
  74. root.setCenter(hbox1);
  75. root.setBottom(hbox2);
  76.  
  77. comboBox.setOnAction(event -> {
  78.  
  79. if (checkboxItalic.isSelected() && checkboxBold.isSelected()) {
  80. label2.setFont(
  81. Font.font(comboBox.getValue(), FontWeight.BOLD, FontPosture.ITALIC, comboBox1.getValue()));
  82. } else if (checkboxItalic.isSelected()) {
  83. label2.setFont(
  84. Font.font(comboBox.getValue(), FontWeight.NORMAL, FontPosture.ITALIC, comboBox1.getValue()));
  85. } else if (checkboxBold.isSelected()) {
  86. label2.setFont(
  87. Font.font(comboBox.getValue(), FontWeight.BOLD, FontPosture.REGULAR, comboBox1.getValue()));
  88. } else
  89. label2.setFont(
  90. Font.font(comboBox.getValue(), FontWeight.THIN, FontPosture.REGULAR, comboBox1.getValue()));
  91.  
  92. // label2.setFont(Font.font(label2.getFont().getFamily(),
  93. // FontWeight.THIN,
  94. // FontPosture.REGULAR,label2.getFont().getSize()));
  95. });
  96.  
  97. comboBox1.setOnAction(event -> {
  98.  
  99. if (checkboxItalic.isSelected() && checkboxBold.isSelected()) {
  100. label2.setFont(
  101. Font.font(comboBox.getValue(), FontWeight.BOLD, FontPosture.ITALIC, comboBox1.getValue()));
  102. } else if (checkboxItalic.isSelected()) {
  103. label2.setFont(
  104. Font.font(comboBox.getValue(), FontWeight.NORMAL, FontPosture.ITALIC, comboBox1.getValue()));
  105. } else if (checkboxBold.isSelected()) {
  106. label2.setFont(
  107. Font.font(comboBox.getValue(), FontWeight.BOLD, FontPosture.REGULAR, comboBox1.getValue()));
  108. } else
  109. label2.setFont(
  110. Font.font(comboBox.getValue(), FontWeight.NORMAL, FontPosture.REGULAR, comboBox1.getValue()));
  111. // label2.setFont(Font.font(label2.getFont().getFamily(),
  112. // label2.getFont().getSize()));
  113. });
  114.  
  115. checkboxBold.setOnAction(event -> {
  116.  
  117. // label2.setFont(Font.font(comboBox.getValue(), FontWeight.BOLD,
  118. // comboBox1.getValue()));
  119.  
  120. if (checkboxItalic.isSelected() && checkboxBold.isSelected()) {
  121. label2.setFont(Font.font(label2.getFont().getFamily(), FontWeight.BOLD, FontPosture.ITALIC,
  122. label2.getFont().getSize()));
  123. } else if (checkboxBold.isSelected())
  124.  
  125. label2.setFont(Font.font(label2.getFont().getFamily(), FontWeight.BOLD, FontPosture.REGULAR,
  126. label2.getFont().getSize()));
  127.  
  128. else if (checkboxItalic.isSelected())
  129.  
  130. label2.setFont(Font.font(label2.getFont().getFamily(), FontWeight.NORMAL, FontPosture.ITALIC,
  131. label2.getFont().getSize()));
  132.  
  133. else
  134. label2.setFont(Font.font(label2.getFont().getFamily(), FontWeight.NORMAL, FontPosture.REGULAR,
  135. label2.getFont().getSize()));
  136.  
  137. });
  138. checkboxItalic.setOnAction(event -> {
  139.  
  140. // label2.setFont(Font.font(comboBox.getValue(), FontWeight.BOLD,
  141. // FontPosture.ITALIC, comboBox1.getValue()));
  142.  
  143. if (checkboxItalic.isSelected() && checkboxBold.isSelected()) {
  144.  
  145. label2.setFont(Font.font(label2.getFont().getFamily(), FontWeight.BOLD, FontPosture.ITALIC,
  146. label2.getFont().getSize()));
  147. } else if (checkboxItalic.isSelected())
  148. label2.setFont(Font.font(label2.getFont().getFamily(), FontWeight.NORMAL, FontPosture.ITALIC,
  149. label2.getFont().getSize()));
  150. else if (checkboxBold.isSelected())
  151. label2.setFont(Font.font(label2.getFont().getFamily(), FontWeight.BOLD, FontPosture.REGULAR,
  152. label2.getFont().getSize()));
  153. else
  154. label2.setFont(Font.font(label2.getFont().getFamily(), FontWeight.NORMAL, FontPosture.REGULAR,
  155. label2.getFont().getSize()));
  156.  
  157. });
  158.  
  159.  
  160. }
  161.  
  162.  
  163. public static void main(String[] args) {
  164. launch(args);
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement