Java development notes (one hundred thirty-eight) JavaFX box

Introduced in front of the use of JavaFX label control, which refers Label text support Chinese fonts, it in the end what Chinese font support it? Naturally depends on the current operating system are installed fonts for the job which, for the Chinese Windows system, installed by default in bold "SimHei", Arial "NSimSun", italics "FangSong" and italics "KaiTi". AWT and Swing in the system, Font tool supports name into Chinese fonts; but in the JavaFX programming, Font font tools will have to fill in Chinese pinyin. In addition to these four basic fonts, as long as the Chinese system installed Office, it will increase following the Chinese fonts that can be used JavaFX code:
Clerical: LiSu
Young round: YouYuan
Founder Shu body: FZShuTi
Founder Yao body: FZYaoti
Chinese thin black: STXihei
Hua Wenkai body: STKaiti
Chinese italicized: STSong
Chinese Song: STZhongsong
Chinese italics: STFangsong
Chinese Choi: STCaiyun
Chinese amber: STHupo
Chinese official script: STLiti
Chinese Xingkai: STXingkai
Chinese new Wei: STXinwei

In the interface layout, JavaFX also made additional enhancements. The original AWT / Swing frame has three layouts: flow layout, grid layout, the layout of the boundary, but the lack of two common layout: about arranged vertically arranged horizontal layout and vertical layout. Although the layout flow is from left to right, but his party would fit the wrap will not achieve the effect of fixed display line. Grid layout although seemingly single multi-line vertical layout, but the height of each grid is fixed, it is difficult to meet each of the requirements change line highly flexible. AWT and Swing as the last century antique, had stopped the function expansion, but fortunately the timely introduction of a reference JavaFX controls horizontal layout and vertical layout. Wherein the control level is called level control box layout of the HBox, vertical layout of the control box controls the VBox called vertical, Talia nominally box, in fact, with the flow pane, the grid pane, also belong to the large pane boundary pane family. When encoding, HBox and VBox usage flow close pane FlowPane, they can be considered as a special kind of flow panes.
Subsequently by the specific code to demonstrate the role of the horizontal and vertical boxes of the box, in order to better observe the tag within the text box, first define a common method of obtaining getLabel label object, the method implementation code is shown below:

	// Get the specified text and font tags 
	Private getLabel the Label (String text, the Font font) { 
		the Label label = new new the Label (text); // create a label 
		label.setFont (font); // set the label's font 
		label.setAlignment (Pos.CENTER); // set the alignment tab 
		label.setWrapText (true); // set the text wrap support 
		return label; 
	}

 

Then create a horizontal box, and the box were sequentially added to the four text labels associated operation code fragment example is as follows:

		Button btn1 = new Button ( "horizontal arrangement"); // Create a button 
		btn1.setOnAction (new EventHandler <ActionEvent> ( ) {// set button click event 
			@Override 
			public void handle (the ActionEvent the arg0) {// Processing click the event 
				HBox hbox = new HBox (); // create a horizontal box 
				hbox.setAlignment (Pos.CENTER); // set the horizontal alignment of the box 
				. hbox.getChildren () add (getLabel ( " grass on the Plain ", Font.font (" SimHei ", 25))); // add a label to the box level 
				hbox.getChildren (.) add (getLabel ( " a one year old Coorong ", Font.font (" KaiTi ", 25) )); // add a label to the level box 
				hbox.getChildren () add (getLabel ( "wild fire", Font.font ( "NSimSun", 25.))); // add a label to the box level 
				hbox . .getChildren () add (getLabel ( " in spring", Font.font ( "FangSong", 25))); // add a label to the box level 
				borderPane.setCenter (hbox); // the horizontal boundary box into a central pane 
			} 
		});
		. FlowPane.getChildren () add (btn1); // add to the flow pane button

 

Running said test program comprises a code, the window interface click the button as shown below, from left to right can be seen at this time four text labels squeezed in the same horizontal direction.


Then creates a vertical box, the box also sequentially added to four text labels associated operation code fragment example is as follows:

		Button btn2 = new Button ( "vertically aligned"); // Create a button 
		btn2.setOnAction (new EventHandler <ActionEvent> ( ) {// set button click event 
			@Override 
			public void handle (the ActionEvent the arg0) {// Processing click the event 
				VBox vbox = new VBox (); // create a vertical box 
				vbox.setAlignment (Pos.CENTER); // set the vertical alignment of the box 
				. vbox.getChildren () add (getLabel ( " grass on the Plain ", Font.font (" LiSu ", 30))); // add a tag to the vertical box 
				vbox.getChildren (.) add (getLabel ( " a one year old kurong ", Font.font (" YouYuan ", 30) )); // add a tag to the vertical box 
				vbox.getChildren () add (getLabel ( "wild fire", Font.font ( "STXingkai", 30.))); // add a tag to the vertical box 
				vbox . .getChildren () add (getLabel ( " in spring", Font.font ( "STXinwei", 30))); // add a label to the vertical box 
				borderPane.setCenter (vbox); // put vertical boundary box into a central pane 
			} 
		});
		. FlowPane.getChildren () add (btn2); // add to the flow pane button

 

Running said test program again includes a code window interface after clicking the button as shown below, can be seen at this time into four text labels are arranged vertically from top to bottom.

 



See more Java technology articles " Java Development Notes (order) List of chapters "

Guess you like

Origin www.cnblogs.com/pinlantu/p/11368463.html