获取窗口坐标
//窗口大小设置
stage0.xProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observableValue, Number number, Number t1) {
System.out.println("窗口x坐标"+t1 );
}//number为老坐标 t1为新坐标
});
多窗口技术
Stage stage0=new Stage();
stage0.setTitle("今日窗口");
stage0.show();
Stage stage1=new Stage();
stage1.setTitle("dierge");
stage1.show();
package com.example.test1122;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication1 extends Application {
@Override
public void start(Stage stage) {
stage.setTitle("今日摆烂");
stage.getIcons().add(new Image("1.png"));
stage.setHeight(500);
stage.setWidth(1000);
stage.setMaxWidth(1300);
stage.setMaxHeight(1300);
Line line=new Line();
line.setStartY(10.0f);
line.setStartX(10.0f);
line.setEndX(150.0f);
line.setEndY(150.0f);
line.setStroke(Color.RED);
line.setStrokeWidth(10);
Circle circle=new Circle(40,40,30);
circle.setStroke(Color.rgb(111,244,44));
circle.setFill(Color.BLUE);
int x=100;
int y=100;
Text text=new Text(x,y,"雪豹我们上!!!1");
text.setFont(Font.font("楷体",32));
text.setFill(Color.rgb(20,202,02));
text.setRotate(10);//字体旋转
text.setCache(true);
text.setX(100);
text.setY(100);
///
Group group =new Group();
group.getChildren().add(line);
group.getChildren().add(circle);
group.getChildren().add(text);
Scene scene=new Scene(group,300,250);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
字体,图形
换行
text.setWrappingWidth(200);
要用到fxml文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.fx1123.HelloController">
<children>
<TextArea id="text11" layoutX="35.0" layoutY="30.0" prefHeight="200.0" prefWidth="543.0" text="如果我们在应用程序中使用流窗格,则所有节点都包含在流中。 水平流动窗格将窗格的元素包裹在其高度,而垂直流动窗格将元素包裹在其宽度处。 名为FlowPane的类javafx.scene.layout表示Flow Pane。 该类包含7个属性,其中包括 - alignment - 此属性表示“流”窗格内容的对齐方式。 您可以使用setter方法setAllignment()设置此属性。 columnHalignment - 此属性表示垂直流窗格中节点的水平对齐方式。 rowValignment - 此属性表示水平流窗格中节点的垂直对齐方式。 Hgap - 此属性是double类型,它表示流窗格的行/列之间的水平间距。 Orientation - 此属性表示流窗格的方向。 Vgap - 此属性为double类型,它表示流窗格的行/列之间的垂直间距。" />
<Label id="label1" fx:id="label11" layoutX="276.0" layoutY="319.0" text="Label" />
<Button id="button111" fx:id="button11" layoutX="257.0" layoutY="231.0" mnemonicParsing="false" text="welcome" />
</children>
</AnchorPane>
controller控件
package com.example.fx1123;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import java.net.URL;
import java.time.LocalTime;
import java.util.ResourceBundle;
public class HelloController implements Initializable {
@FXML
public Button button11;
@FXML
public Label label11;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
button11.setOnAction(e->{
label11.setText( LocalTime.now().toString());
System.out.println("anxia");
});
}
}
application
package com.example.fx1123;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 800, 500);
stage.getIcons().add(new Image("xuexi.jpg"));
stage.setTitle("Hello!");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
很重要