JavaFX UI components and multimedia

How to put text to the right of a node in a label?

label.setContentDisplay(ContentDisplay.LEFT);

Please note that the relative position is set here! ! !

How to display multiple lines of text in a label?

Label.setWrapText(true);

All methods of Labeled can be used in CheckBox (inheritance relationship)

All member variables are of type property

Why is the getPane() method protected? Why is the data field text protected?

Make them better used in ButtonDemo subclasses (analysis question)

Can all the methods used for Labeled be used for CheckBox?

Yes, because the parent class of CheckBox is ButtonBase, and the parent class of ButtonBase is Labeled, they have an inheritance relationship.

Can I set the graphic attribute of a checkbox to a node?

Can

Can I set the graphic property of a radio button to any node?

Can

How to group radio buttons?

JRadioButton r1,r2; //声明单选按钮

ButtonGroup g1; //声明分组

add(new JLabel("1、该动物是否有毛发?"));

g1=new ButtonGroup(); //初始化分组

r1=new JRadioButton("0.没有");

r2=new JRadioButton("1.有");

g1.add(r1); //将单选按钮添加到分组中

g1.add(r2);

add(r1); //将单选按钮添加到面板中

add(r2);

How to disable editing in a text area?

textArea.setEditable(false);

textArea.setEditable(True)

How to disable the editing function in a text field?

textField.SetEditable(false);

Text area textArea multi-line text

Text field textField input/display string

How to get an item from a combo box? How to get a selected item from a combo box?

ComboBox Why is the combo box special? -->In order to implement the listener mechanism

Use cbo.getItems() to get an item from a combination;

Use cbo.getValue() to get a selected item from a combo box.

What event will the ComboBox fire when a new item is selected?

ActionEvent event

How to create an observable list with an array of strings?

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

public class Main {
    public static void main(String[] args) {
        // 创建一个字符串数组
        String[] array = {"Apple", "Banana", "Cherry", "Date"};

        // 使用FXCollections.observableArrayList方法将数组转换为ObservableList
        ObservableList<String> list = FXCollections.observableArrayList(array);

        // 添加一个监听器,当列表发生变化时,打印新的列表
        list.addListener((ListChangeListener<? super String>) change -> {
            System.out.println("List changed: " + list);
        });

        // 修改列表
        list.add("Elderberry");
        list.remove("Banana");
    }
}

What selection modes are available for list views? What is the default selection mode? How to set a selection mode?

SelectionMode.MULTIPLE,SelectionMode.SINGLE;

Default: setSelectionIndex(int ​​index);

Selection mode: lv. get SelectionModel(). set SelectionMode(SelectionMode.MULTIPLE)

get returns an instance! ! !

ListView can be single-selected or multiple-selected.

How to create a horizontal scrollbar? How to create a vertical scrollbar?

Use new ScrollBall() to create a scroll bar and call the following two methods

setOrientation(Orientation.HORIZONTAL) 水平

setOrientation(Orientation.VERTICAL)   垂直

How to create a horizontal slider? How to create a vertical slider?

Use new Slider() to create a slider and call the following two methods respectively.

setOrientation(Orientation.HORIZONTAL)  水平

setOrientation(Orientation.VERTICAL)    垂直

How to add a listener to handle property value changes of the slider?

Use sl.valueProperty().addListener(ov->statements) to add a listener

How to create a Media object from a URL? How to create a MediaPlayer? How to create a MediaView?

(new an object)

new Media(url);

new MediaPlayer(media);

new MediaView(mediaPlayer);

Play media: media.play();

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;

public class Main extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        // 从URL创建一个Media对象
        String url = "http://example.com/myvideo.mp4";
        Media media = new Media(url);

        // 创建一个MediaPlayer
        MediaPlayer mediaPlayer = new MediaPlayer(media);

        // 创建一个MediaView
        MediaView mediaView = new MediaView(mediaPlayer);

        // 创建一个布局
        StackPane root = new StackPane();
        root.getChildren().add(mediaView);

        // 创建一个场景
        Scene scene = new Scene(root, 600, 400);

        // 设置舞台
        primaryStage.setScene(scene);
        primaryStage.show();

        // 播放媒体
        mediaPlayer.play();
    }
}

UML class diagram for Node

Guess you like

Origin blog.csdn.net/mynameispy/article/details/135305180