javafx各种控件

这篇具有很好参考价值的文章主要介绍了javafx各种控件。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、RadioButton Controls

(1)基础

RadioButton Controls经常以组的形式出现,它可以让用户进行选择。

radiobutton控件在radiobutton类中,需要导javafx.scene.control包。

RadioButton radio1 = new RadioButton("Choice 1");

注意,我们在RadioButton旁边显示的字符串作为参数传递给RadioButton 类的构造函数的参数。你可以选择省略字符串参数来创建一个没有文本的RadioButton控件。

RadioButton radio1 = new RadioButton();

RadioButton控件通常被分组在一个toggle(切换)组中。一个toggle组中只有一个RadioButton 控件可以被选中。点击一个RadioButton可以选择这个控件,并自动地取消这个toggle中已选择的其他RadioButton。因为一个toggle组中只有一个RadioButton 可以被选中,所以RadioButton控件被认为是互斥的。

(2)一组RadioButton

要创建toggle类,我们需要ToggleGroup class,它在javafx.scene.control package中。

ToggleGroup myToggleGroup = new ToggleGroup();

创建一个ToggleGroup对象后,你必须调用每个RadioButton控件的setToggleGroup方法 以将它们添加到ToggleGroup中。

// Create some RadioButtons.
RadioButton radio1 = new RadioButton("Option 1");
RadioButton radio2 = new RadioButton("Option 2");
RadioButton radio3 = new RadioButton("Option 3");
// Create a ToggleGroup.
ToggleGroup radioGroup = new ToggleGroup();
// Add the RadioButtons to the ToggleGroup.
radio1.setToggleGroup(radioGroup);
radio2.setToggleGroup(radioGroup);
radio3.setToggleGroup(radioGroup);

(3) RadioButton的其他方法

为了确定一个RadioButton是否被选中,你可以调用RadioButton类的isSelected方法。该方法返回一个布尔值,表示该RadioButton是否被选中。如果RadioButton被选中,该方法返回true。否则,它返回false。

if (radio1.isSelected())
{
 // Code here executes if the radio
 // button is selected.
}

除了在用户点击完之后选中RadioButton控件,还可以程序选择控件,比如有时候我们希望默认选择某个控件。我们可以用setSelected方法在代码中选择。 如果你向该方法传递true,RadioButton将被选中,就像用户点击它一样,如果你把false作为参数传给setSelected方法,RadioButton将被取消选择。

radio1.setSelected(true);

(4)例子 

以我们之前的转换器为例:

import javafx.application.Application;
        import javafx.stage.Stage;
        import javafx.scene.Scene;
        import javafx.scene.layout.HBox;
        import javafx.scene.layout.VBox;
        import javafx.geometry.Pos;
        import javafx.geometry.Insets;
        import javafx.scene.control.Label;
        import javafx.scene.control.TextField;
        import javafx.scene.control.Button;
        import javafx.scene.control.RadioButton;
        import javafx.scene.control.ToggleGroup;
        import javafx.event.EventHandler;
        import javafx.event.ActionEvent;

/**
 Metric Converter application
 */

public class MetricConverter extends Application
{
    // Fields
    private TextField kiloTextField;
    private Label resultLabel;
    private RadioButton milesButton;
    private RadioButton feetButton;
    private RadioButton inchesButton;

    public static void main(String[] args)
    {
        // Launch the application.
        launch(args);
    }

    @Override
    public void start(Stage primaryStage)
    {
        // Create a Label to display a prompt.
        Label promptLabel = new Label("Enter a distance in kilometers:");

        // Create a TextField for input.
        kiloTextField = new TextField();

        // Create the RadioButton controls.
        milesButton = new RadioButton("Convert to Miles");
        feetButton = new RadioButton("Convert to Feet");
        inchesButton = new RadioButton("Convert to Inches");

        // Select the milesButton control.
        milesButton.setSelected(true);

        // Add the RadioButton controls to a ToggleGroup.
        ToggleGroup radioGroup = new ToggleGroup();
        milesButton.setToggleGroup(radioGroup);
        feetButton.setToggleGroup(radioGroup);
        inchesButton.setToggleGroup(radioGroup);

        // Create a Button to perform the conversion.
        Button calcButton = new Button("Convert");

        // Register the event handler.
        calcButton.setOnAction(new CalcButtonHandler());

        // Create an empty Label to display the result.
        resultLabel = new Label();

        // Put the promptLabel and the kiloTextField in an HBox.
        HBox promptHBox = new HBox(10, promptLabel, kiloTextField);

        // Put the RadioButtons in an HBox.
        HBox radioHBox = new HBox(20, milesButton, feetButton,
                inchesButton);

        // Put everything in a VBox.
        VBox mainVBox = new VBox(10, promptHBox, radioHBox, calcButton,
                resultLabel);

        // Set the VBox's alignment to center.
        mainVBox.setAlignment(Pos.CENTER);

        // Set the VBox's padding to 10 pixels.
        mainVBox.setPadding(new Insets(10));

        // Create a Scene.
        Scene scene = new Scene(mainVBox);

        // Add the Scene to the Stage.
        primaryStage.setScene(scene);

        // Set the stage title.
        primaryStage.setTitle("Metric Converter");

        // Show the window.
        primaryStage.show();
    }

    /**
     Event handler class for calcButton
     */

    class CalcButtonHandler implements EventHandler<ActionEvent>
    {
        @Override
        public void handle(ActionEvent event)
        {
            // Constants for the conversion factors.
            final double MILES_CONVERSION = 0.6214;
            final double FEET_CONVERSION = 3281.0;
            final double INCHES_CONVERSION = 39370.0;

            // Variable to hold the result
            double result = 0;

            // Get the kilometers.
            double kilometers = Double.parseDouble(kiloTextField.getText());

            // Perform the selected conversion.
            if (milesButton.isSelected())
                result = kilometers * MILES_CONVERSION;

            if (feetButton.isSelected())
                result = kilometers * FEET_CONVERSION;

            if (inchesButton.isSelected())
                result = kilometers * INCHES_CONVERSION;

            // Display the results.
            resultLabel.setText(String.format("%,.2f", result));
        }
    }
}

javafx各种控件

javafx各种控件

注意:

当我们的handler类需要使用某些变量时,要在类的域中先声明这些变量,比如这个例子中的kiloTextField, resultLabel milesButton, feetButton

setSelected方法设置了一个默认项。

isSelected方法确定选中的是哪一个控件。

(5)对不同选择进行反馈

import javafx.application.Application;
        import javafx.stage.Stage;
        import javafx.scene.Scene;
        import javafx.scene.layout.HBox;
        import javafx.scene.layout.VBox;
        import javafx.geometry.Pos;
        import javafx.geometry.Insets;
        import javafx.scene.image.Image;
        import javafx.scene.image.ImageView;
        import javafx.scene.control.RadioButton;
        import javafx.scene.control.ToggleGroup;
        import javafx.event.EventHandler;
        import javafx.event.ActionEvent;

/**
 A RadioButton ActionEvent Demo
 */

public class RadioButtonEvent extends Application
{
    public static void main(String[] args)
    {
        // Launch the application.
        launch(args);
    }

    @Override
    public void start(Stage primaryStage)
    {
        // Create two Image objects.
        Image flowerImage = new Image("file:Flower.jpg");
        Image sunsetImage = new Image("file:Sunset.jpg");

        // Create an ImageView object.
        ImageView imageView = new ImageView(flowerImage);

        // Resize the ImageView, preserving its aspect ratio.
        imageView.setFitWidth(200);
        imageView.setPreserveRatio(true);

        // Put the ImageView in an HBox.
        HBox imageHBox = new HBox(imageView);

        // Center the HBox contents.
        imageHBox.setAlignment(Pos.CENTER);

        // Create the RadioButtons.
        RadioButton flowerRadio = new RadioButton("Flower");
        RadioButton sunsetRadio = new RadioButton("Sunset");

        // Select the flowerRadio control.
        flowerRadio.setSelected(true);

        // Add the RadioButtons to a ToggleGroup.
        ToggleGroup radioGroup = new ToggleGroup();
        flowerRadio.setToggleGroup(radioGroup);
        sunsetRadio.setToggleGroup(radioGroup);

        // Register an ActionEvent handler for the flowerRadio.
        flowerRadio.setOnAction(event −>
                {
                        imageView.setImage(flowerImage);
 });

        // Register an event handler for the sunsetRadio.
        sunsetRadio.setOnAction(event −>
                {
                        imageView.setImage(sunsetImage);
 });

        // Add the RadioButtons to a VBox.
        VBox radioVBox = new VBox(10, flowerRadio, sunsetRadio);

        // Give the radioVBox some padding.
        radioVBox.setPadding(new Insets(30));

        // Add everything to a VBox.
        VBox mainVBox = new VBox(10, imageHBox, radioVBox);

        // Create a Scene with the HBox as its root node.
        Scene scene = new Scene(mainVBox);

        // Add the Scene to the Stage.
        primaryStage.setScene(scene);

        // Show the window.
        primaryStage.show();
    }
}

javafx各种控件

 二、CheckBox Controls

checkbox控件常被用来让用户选择一系列yes/no的问题,大概长这样:

javafx各种控件

 和之前的radiobutton一样,checkbox也有两种构造器,一种显示文字,一种不显示:

CheckBox check1 = new CheckBox("Macaroni");
CheckBox check1 = new CheckBox();

是否被选中:

if (check1.isSelected())
{
 // Code here executes if the check
 // box is selected.
}

默认选中:

check1.setSelected(true);

例子:

import javafx.application.Application;
        import javafx.stage.Stage;
        import javafx.scene.Scene;
        import javafx.scene.layout.HBox;
        import javafx.scene.layout.VBox;
        import javafx.geometry.Pos;
        import javafx.geometry.Insets;
        import javafx.scene.control.Label;
        import javafx.scene.control.CheckBox;
        import javafx.scene.control.Button;
        import javafx.event.EventHandler;
        import javafx.event.ActionEvent;

/**
 CheckBox Demo application
 */

public class PizzaToppings extends Application
{
    // Fields
    CheckBox pepperoniCheckBox;
    CheckBox cheeseCheckBox;
    CheckBox anchoviesCheckBox;
    Label totalLabel;

    public static void main(String[] args)
    {
// Launch the application.
        launch(args);
    }

    @Override
    public void start(Stage primaryStage)
    {
// Create the CheckBoxes.
        pepperoniCheckBox = new CheckBox("Pepperoni $3.00");
        cheeseCheckBox = new CheckBox("Cheese $2.00");
        anchoviesCheckBox = new CheckBox("Anchovies $1.00");

// Create the Button control.
        Button totalButton = new Button("Get Total");

// Register the event handler.
        totalButton.setOnAction(new TotalButtonHandler());

// Create a Label for the total.
        totalLabel = new Label("$0.00");

// Put the CheckBoxes in a VBox.
        VBox checkBoxVBox = new VBox(10, pepperoniCheckBox,
                cheeseCheckBox, anchoviesCheckBox);

// Create another VBox to use as the root node.
        VBox mainVBox = new VBox(10, checkBoxVBox, totalButton,
                totalLabel);

// Set the main VBox's alignment to center.
        mainVBox.setAlignment(Pos.CENTER);

// Set the main VBox's padding to 10 pixels.
        mainVBox.setPadding(new Insets(10));

// Create a Scene.
        Scene scene = new Scene(mainVBox);

// Add the Scene to the Stage.
        primaryStage.setScene(scene);

// Show the window.
        primaryStage.show();
    }

    /**
     Event handler class for totalButton
     */

    class TotalButtonHandler implements EventHandler<ActionEvent>
    {
        @Override
        public void handle(ActionEvent event)
        {
// Variable to hold the result
            double result = 0;

// Add up the toppings.
            if (pepperoniCheckBox.isSelected())
                result += 3.0;

            if (cheeseCheckBox.isSelected())
                result += 2.0;

            if (anchoviesCheckBox.isSelected())
                result += 1.0;

// Display the results.
            totalLabel.setText(String.format("$%,.2f", result));
        }
    }
}

javafx各种控件

 三、ListView Controls

(1)创建

listview控件可以显示一系列item并让用户在其中选择。

javafx各种控件

 注意最上面的ListView没有 没有滚动条,但最下面的一个有。当ListView中包含的项目超过所提供的空间时,滚动条会自动出现。当ListView包含的项目超过了所提供的空间所能显示的数量时,滚动条就会自动出现。

用ListView类(在javafx.scene.control包中)创建一个ListView控件:

ListView<string> dogListView = new ListView<>();

我们还可以添加内容:

dogListView.getItems().addAll("Poodle", "Great Dane", "Labrador", "Terrier");

我们还可以设定页面的大小:

ListView<string> catListView = new ListView<>();
catListView.setPrefSize(120, 100);
catListView.getItems().addAll("Siamese", "Persian", "Bobtail",
 "Burmese", "Tabby");

(2)一些方法 

你可以使用ListView类的getSelectionModel().getSelectedItem()方法获得当前被选中的项目。下面的代码获取当前在控件中被选中的项目,并将其分配给一个名为selected的字符串。

String selected = listView.getSelectionModel().getSelectedItem();

如果当前没有选中的,这个方法就会返回null。

下面看一个完整的例子:

import javafx.application.Application;
        import javafx.stage.Stage;
        import javafx.scene.Scene;
        import javafx.scene.control.ListView;
        import javafx.scene.control.Label;
        import javafx.scene.control.Button;
        import javafx.scene.layout.VBox;
        import javafx.geometry.Pos;
        import javafx.geometry.Insets;

public class ListViewDemo1 extends Application
{
    public static void main(String[] args)
    {
// Launch the application.
        launch(args);
    }

    @Override
    public void start(Stage primaryStage)
    {
// Create a ListView of Strings.
        ListView<string> listView = new ListView<>();
        listView.setPrefSize(120, 100);
        listView.getItems().addAll("Steve", "Bethany", "Will", "Katrina");

// Create a Label to display the selection.
        Label selectedNameLabel = new Label("Select a Name");

// Create a Button to get the selection.
        Button getButton = new Button("Get the Selection");

// Create an event handler for the Button.
        getButton.setOnAction(event −>
                {
// Get the selected name.
                        String selected = listView.getSelectionModel().getSelectedItem();

// Display the selected name in the Label.
        selectedNameLabel.setText(selected);
});

// Add the controls to a VBox.
        VBox vbox = new VBox(10, listView, selectedNameLabel, getButton);
        vbox.setPadding(new Insets(10));
        vbox.setAlignment(Pos.CENTER);

// Create a Scene and display it.
        Scene scene = new Scene(vbox);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

javafx各种控件

ListView控件中的每个项目都被分配了一个索引,以标记项目的位置。第一个项目 (是存储在列表顶部的项目)的索引为0,第二个项目的索引为1,以此类推。你可以使用ListView类的getSelectionModel().getSelectedIndex()方法获得当前被选中的项目的索引。

int index = lististView.getSelectionModel().getSelectedIndex();

如果没有被选中的,方法会返回-1.我们也可以用这个方法确定用户是否选择了某一项。

如果我们想在用户选中某一项时立马执行一个操作,我们可以写一个handler。

listView.getSelectionModel().selectedItemProperty().addListener(event −> {
 // Write event handling code here ...
});

还是看之前的例子,我们把button取消,改为当用户选择了一项,就立马显示选择的那项:

javafx各种控件

import javafx.application.Application;
        import javafx.stage.Stage;
        import javafx.scene.Scene;
        import javafx.scene.control.ListView;
        import javafx.scene.control.Label;
        import javafx.scene.layout.VBox;
        import javafx.geometry.Pos;
        import javafx.geometry.Insets;

public class ListViewDemo3 extends Application
{
    public static void main(String[] args)
    {
// Launch the application.
        launch(args);
    }

    @Override
    public void start(Stage primaryStage)
    {
// Create a ListView of Strings.
        ListView<string> listView = new ListView<>();
        listView.setPrefSize(120, 100);
        listView.getItems().addAll("Steve", "Bethany", "Will", "Katrina");

// Create a Label to display the selection.
        Label selectedNameLabel = new Label("Select a Name");

// Create an event handler for the ListView control.

        listView.getSelectionModel().selectedItemProperty().addListener(event −>
                {
// Get the selected name.
                        String selected = listView.getSelectionModel().getSelectedItem();

// Display the selected name in the Label.
        selectedNameLabel.setText(selected);
});

// Add the controls to a VBox.
        VBox vbox = new VBox(10, listView, selectedNameLabel);
        vbox.setPadding(new Insets(10));
        vbox.setAlignment(Pos.CENTER);

// Create a Scene and display it.
        Scene scene = new Scene(vbox);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

(3)添加项目 

ListView控件的getItems().addAll()方法将项目添加到ListView中。如果ListView 已经包含了项目,getItems().addAll()方法不会擦除现有的项目,而是将新项目添加到 新项目添加到现有的列表中。所以ListView将包含旧项和新项。
有时这是你想要的行为,但在其他情况下,你可能想用一个全新的ListView替换现有的内容。
用一个全新的项目列表来替换ListView的现有内容。在这种情况下,你可以使用 getItems().setAll()方法。getItems().setAll()方法将用一个新的项目列表替换ListView控件现有的项目。

// Create a ListView.
ListView<String> listView = new ListView<>();
listView.getItems().addAll("Monday", "Tuesday", "Wednesday");
// Replace the existing items with a new list.
listView.getItems().setAll("Thursday", "Friday", "Saturday");

有时候我们希望将一个数组或者一个arraylist直接变成一个listview,这需要我们把数组或者arraylist变成ObservableList,再把ObservableList变成listview。

数组:

// Create a String array.
String[] strArray = {"Monday", "Tuesday", "Wednesday"};
// Convert the String array to an ObservableList.
ObservableList<String> strList =
 FXCollections.observableArrayList(strArray);
// Create a ListView control.
ListView<String> listView = new ListView<>(strList);

arraylist:

// Create an ArrayList of Strings.
ArrayList<String> strArrayList = new ArrayList<>();
strArrayList.add("Monday");
strArrayList.add("Tuesday");
strArrayList.add("Wednesday");
// Convert the ArrayList to an ObservableList.
ObservableList<String> strList =
 FXCollections.observableArrayList(strArrayList);
// Create a ListView control.
ListView<String> listView = new ListView<>(strList);

当然也也有不用构造器,而使用刚刚提到的setAll()addAll()方法:

// Create a String array.
String[] strArray = {"Monday", "Tuesday", "Wednesday"};
// Convert the String array to an ObservableList.
ObservableList<String> strList =
 FXCollections.observableArrayList(strArray);
// Create a ListView control.
ListView<String> listView = new ListView<>();
// Populate the ListView control:
listView.getItems().addAll(strList);

(4)选择模式

lsitview控件有两个模式,它可以一次选择一个,也可以一次选择多个。

单一选择模式下,一次只能选择一个项目。当一个项目被选中时,之前被选中的项目就会被取消选择,这是默认的选择模式。
多重区间选择模式下,可以选择多个项目。要选择连续的多个项目,用户点击第一个项目,按住键盘上的Shift键,然后点击最后一个项目;要选择不连续的项目,用户按住键盘上的Ctrl键(或Mac键盘上的Command键),然后点击每个项目。

javafx各种控件

 要选择模式,需要调用getSelectionModel().setSelectionMode()方法,它接收一个枚举类作为其参数:SelectionMode.MULTIPLE,SelectionMode.SINGLE。

listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

当ListView控件处于多选模式时,用户可以选择一个以上的项目。在这种情况下getSelectionModel().getSelectedItem()方法将只返回最后选择的项目。同样地,
getSelectionModel().getSelectedIndex()方法将只返回最后选择的项目的索引。要想返回所有选定的值,我们需要用下面的方法(注意s)
getSelectionModel().getSelectedItems()-该方法返回一个只读的ObservableList,其中包括所有选定的项目
getSelectionModel().getSelectedIndices()-该方法返回一个只读的ObservableList,其中包括被选中的项目的index。

下面看一个例子:

import javafx.application.Application;
        import javafx.stage.Stage;
        import javafx.scene.Scene;
        import javafx.scene.control.ListView;
        import javafx.scene.control.SelectionMode;
        import javafx.collections.ObservableList;
        import javafx.scene.control.Label;
        import javafx.scene.control.Button;
        import javafx.scene.layout.VBox;
        import javafx.geometry.Pos;
        import javafx.geometry.Insets;

public class ListViewDemo4 extends Application
{
    public static void main(String[] args)
    {
// Launch the application.
        launch(args);
    }

    @Override
    public void start(Stage primaryStage)
    {
// Constants for the ListView sizes
        final double WIDTH = 120, HEIGHT = 140;

// Create a ListView of the names of the months.
        ListView<String> listView1 = new ListView<>();
        listView1.setPrefSize(WIDTH, HEIGHT);
        listView1.getSelectionModel().setSelectionMode(
                SelectionMode.MULTIPLE);
        listView1.getItems().addAll(
                "January", "February", "March", "April", "May",
                "June", "July", "August", "September", "October",
                "November", "December");

// Create an empty ListView to show the selections.
        ListView<String> listView2 = new ListView<>();
        listView2.setPrefSize(WIDTH, HEIGHT);

// Create a Button to get the selections.
        Button getButton = new Button("Get Selections");

// Register an event handler for the Button.
        getButton.setOnAction(event −>
                {
// Get the ObservableList of selected items.
                        ObservableList<String> selections =
                                listView1.getSelectionModel().getSelectedItems();

// Add the selections to the 2nd ListView.
        listView2.getItems().setAll(selections);
});

// Add the controls to a VBox.
        VBox vbox = new VBox(10, listView1,
                listView2, getButton);
        vbox.setPadding(new Insets(10));
        vbox.setAlignment(Pos.CENTER);

// Create a Scene and display it.
        Scene scene = new Scene(vbox);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

javafx各种控件

 注意这个程序是如何读取选中的内容并将其转换成下面那个listview显示的内容的。文章来源地址https://www.toymoban.com/news/detail-491026.html

到了这里,关于javafx各种控件的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • JavaFX增删改查&其他控件

     小技巧 增删改查思路   --查 底层select * from 表 where sname like \\\'%%\\\' --1.拿文本框的 --2.调模糊查询的方法 myShow(\\\"\\\")   --删 底层 delete from tb_stu where sid=? --1.想方设法拿学号 --1.先拿到用户所选中的学生对象 Student --2.调用方法传对象.getSid()   --增 开个界面(把自己传递过去 为

    2024年01月23日
    浏览(39)
  • JavaFx 用户界面控件3——TableView

    ableView是JavaFX提供的一个强大的控件,可以用于显示表格数据。它通过为TableView设定items属性(存储行数据的ObservableList对象)和列属性(TableColumn对象)来完成数据填充与展示。 以下是一个简单的TableView的使用示例:  1.1 TableView 选中事件 演示应用程序是一个 TableView 和一对

    2024年02月07日
    浏览(37)
  • 【WinForm详细教程一】WinForm中的窗体、Label、TextBox及Button控件、RadioButton和CheckBox、ListBox

    .sln文件 :解决方案文件 位置引用 bin文件夹 : 存放项目的编译结果 exe dll debug 调试 release 发布 pdb 位置信息–调试 obj文件夹 object 编译过程中生成的中间临时文件 加快编译速度 Properties 引用 添加引用 --选择需要的程序集 App.config 配置文件 .csproj 项目文件 位置引用 双击打开

    2024年02月08日
    浏览(37)
  • JavaFX 用户界面控件1——ChoiceBox ComboBox

    JavaFX的ChoiceBox是一个用户界面控件,用于向用户显示一个选项列表,并允许用户从中选择一个或多个选项。下面是一个ChoiceBox的简单示例和使用介绍: 首先,导入JavaFX的相关类: import javafx.application.Application; import javafx.collections.FXCollections; import javafx.scene.Scene; import javafx.sce

    2024年02月09日
    浏览(28)
  • JAVAFX中ChoiceBox控件使用教程(用到scenebuilder)

    ChoiceBox控件负责选择合适的选项,单独使用JAVAFX很容易实现。但如果使用到scenebuiler,ChoiceBox控件操作则较为麻烦,为了学会这个控件的基本使用,我搜寻了很多资料,希望能帮到大家。控件效果展示如下。 首先放置控件至合适位置后,将生成的Controller类的代码复制至相应的

    2024年02月11日
    浏览(26)
  • 基于JavaFX的扫雷游戏实现(五)——设置和自定义控件

      它来了它来了,最后一期终于来了。理论上该讲的全都讲完了,只剩下那个拖了好几期的自定义控件和一个比较没有存在感的设置功能没有讲。所以这次就重点介绍它们俩吧。   首先我们快速浏览下设置的实现,上图:   然后是控制器代码: SettingsController.java   

    2024年02月13日
    浏览(26)
  • openlayers controls基础知识

    控件是一个可见的小部件,其 DOM 元素位于屏幕上的固定位置。 它们可以涉及用户输入(按钮),或者仅提供信息; 位置是使用 CSS 确定的。 默认情况下,它们放置在 CSS 类名为 ol-overlaycontainer-stopevent 的容器中,但可以使用任何外部 DOM 元素。 .在Openlayers中多数Controls直接可

    2024年02月12日
    浏览(26)
  • JavaFX入门和网格布局面板的使用,Dao层交互,舞台与场景切换以及其他控件的使用

    网格布局 将整个面板划分为若干个格子 , 每个格子的大小是一样的 , 每个格子中可以放置一个控件(布局) , 类似于表格的方式。在网格布局 中放入控件的时候 , 还需要指定位置。 我们将要排出这个布局 , 也就是登陆页面的优化版本 位置原理讲解 以网格布局的思维来拆分

    2024年02月04日
    浏览(32)
  • JavaFx基础学习【三】:Scene

    目录 前言 一、介绍 二、代码体验 三、结果演示 四、总结 五、其他章节 如果你还没有看过前面的文章,可以通过以下链接快速前往学习: JavaFx基础学习【一】:基本认识_明天再去学习的博客-CSDN博客 JavaFx基础学习【二】:Stage_明天再去学习的博客-CSDN博客 Scene,就是场景

    2024年02月13日
    浏览(28)
  • QT各种控件常用样式表qss示例

    目录 1、表格控件QTableWidget和QTableView 2、滚动条QScrollBar 这个控件比较复杂,里面包含了滑动条、表头(又细分为内容区/空白区)、表格、整体、左上角按钮等多种不同的元素,他们之间有复杂的叠层关系。需要通过各种“选择器”来指定样式的作用范围。 本文由【暴躁的野

    2024年02月16日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包