A method for diversifying filling components of a JavaFX form component and listening to states

CN122985142APending Publication Date: 2026-10-27XIAN LIUGU SOFTWARE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411710538.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2026-10-27

AI Technical Summary

Technical Problem

[0003]为了解决上述背景技术中提到的Javafx控件TableView表单支持的填充组件,单一、表单中编写自定义填充组件时,逻辑复杂,需要定义很多重复结构的问题,本发明提供了一种JavaFX表单组件多样化填充组件及监听状态的方法,该方法重新设计了一种对TableView中的组件添加方式,实现便捷式的表单多样化填充组件,且支持定义每个单元格内放置的组件类型,且单元格中的每个自定义组件都实现了双向绑定监听功能

Benefits of technology

本发明提供的方法实现单元格中自定义组件填充的复用,利用注册自定义组件的形式,在表单初始化时进行自定义组件类型的注册,在表单单元格中可以直接引用自定义组件的id进行复用,极大的优化了代码结构和提高了开发效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122985142A_ABST
    Figure CN122985142A_ABST
Patent Text Reader

Abstract

The application provides a JavaFX form component diversified filling component and a method for monitoring state, and relates to the technical field of Java desktop application development. The method comprises the following steps: defining a customized component which needs to be filled in a form, and registering in a form factory; defining row data objects and column objects in the form, so that the attributes of each column object are limited to preset attributes; defining a cell data monitoring interface, realizing real-time monitoring of data state changes through the cell data monitoring interface, and realizing specific business logic in the monitoring interface; creating an initial form, adding the set form object to the form component, completing the filling of the customized component in the form and the loading of data, rendering the data in the form, and real-time monitoring of each data change. The method realizes a convenient form diversified filling component, supports the definition of the component type placed in each cell, and each customized component in the cell realizes a bidirectional binding monitoring function.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of Java desktop application development technology, specifically to a method for diversifying the population components and listening to the status of JavaFX form components. Background Technology

[0002] When developing desktop applications using JavaFX, the user interface involves many components, such as buttons, text boxes, checkboxes, labels, canvases, or some custom components. The position, size, and interactive events of these components in the front-end graphical interface require a lot of tedious work to adjust. The TableView component provided by JavaFX is a form control, and the form cells support placing components from other JavaFX subclasses. In traditional development, the design of a user graphical interface and the implementation of the corresponding control interaction logic may vary from developer to developer in terms of style and structure. The ability to customize the form at the cell level using the features of TableView is a problem that developers urgently need to solve. The original form structure requires defining and adding different components each time, which requires repeated definition and results in poor versatility, a lot of repetitive work, and low development efficiency during project development. Summary of the Invention

[0003] To address the issues mentioned in the background section regarding the limited number of fill components supported by the JavaFX control TableView, the complexity of custom fill components in forms, and the need to define numerous repetitive structures, this invention provides a method for diversifying fill components and monitoring states in JavaFX forms. This method redesigns the way components are added to TableView, enabling convenient and diverse fill components for forms. It also supports defining the type of component placed in each cell, and each custom component in the cell implements a two-way binding monitoring function.

[0004] Specifically, this invention provides a method for diversifying the population components and listening to the state of JavaFX form components, including: Define the custom components that need to be filled in the form and register them in the form factory, so that each type of component in the form factory object has a unique ID; Define row data objects and column objects in the form, and restrict the properties of each column object to preset properties; Define a cell data listening interface to monitor data status changes in real time, and implement specific business logic in the listening interface. Create an initial form, add the configured form object to the form component, and complete the filling and data loading of the custom component in the form; Render the data in the form and monitor changes in each data point in real time.

[0005] As a further explanation of the present invention, the definition of custom components that need to be filled in the form and the registration in the form factory, so that each type of component in the form factory object has a unique ID identifier, specifically includes: Define a custom cell object, and define the trigger logic and display style of the cell object; Set the packaging type number to be displayed for the cell object, where the number is an integer; Verify whether the cell object is a duplicate of an existing cell object in the form factory object; Register unique cell objects to the form factory object.

[0006] As a further explanation of the present invention, the specific attributes of each column object in the form can be defined by generics to restrict the attributes of the column objects.

[0007] As a further explanation of the present invention, the defined cell data monitoring interface includes: Define the listener parameters for the form entity class object. The member listener objects of the form entity class include the wrapper property PackPropert and its corresponding listener class object property ObjectProperty.

[0008] As a further explanation of the present invention, the real-time monitoring of data state changes through the cell data monitoring interface includes: Each column object implements the setCellFactory() listener method, which returns an LGTableCell table cell object.

[0009] As a further explanation of the present invention, the real-time monitoring of data state changes through the cell data monitoring interface further includes: Each column of objects implements the setCellValueFactory() listener method, which returns an ObjectProperty object.

[0010] As a further explanation of the present invention, when adding a form object to a form component, it can be directly called through the ID registered in the form factory where it needs to be referenced.

[0011] Compared with the prior art, the present invention has the following beneficial technical effects: The method provided by this invention enables the reuse of custom component filling in cells. By registering custom components, the custom component type is registered during form initialization. The custom component's ID can be directly referenced in the form cell for reuse, which greatly optimizes the code structure and improves development efficiency.

[0012] The method provided by this invention redefines the content filling of the TableView component (TableCell object), allowing users to quickly bind any component to each cell. This enables a convenient and diverse form filling component, which is highly versatile in project development. It reduces the original tedious process of writing repetitive code and interactive events for each component, thereby improving development efficiency.

[0013] The method provided by this invention enables each custom component in a cell to implement a two-way binding listening function. Any data change of the component placed in the cell can be responded to in real time in the listening interface, and developers can develop business logic in the listening interface.

[0014] Other features and advantages of this technical solution will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the technical solution. The objectives and other advantages of this technical solution can be realized and obtained by means of the structures particularly pointed out in the written description and the accompanying drawings.

[0015] The technical solution of this invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0016] The accompanying drawings are provided to further illustrate the present technical solution and form part of the specification. They are used together with the embodiments of the present technical solution to explain the present technical solution, but do not constitute a limitation thereof. In the accompanying drawings: Figure 1 The flowchart illustrates the method for diversifying the JavaFX form component's population components and monitoring its state, as provided by this invention.

[0017] Figure 2 This is a flowchart illustrating the definition of custom components and their registration in the form factory in this invention.

[0018] Figure 3 This is a diagram showing the filling effect of a custom component in a form according to an embodiment of the present invention. Detailed Implementation

[0019] The preferred embodiments of this technical solution are described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are only for illustration and explanation of this technical solution and are not intended to limit this technical solution.

[0020] like Figure 1 As shown, this invention provides a method for diversifying the population components and listening to the state of JavaFX form components, including the following process: 1. Define the custom components that need to be filled in the form and register them in the form factory, so that each type of component in the form factory object has a unique ID.

[0021] Specifically, such as Figure 2 As shown, the above definition and registration process includes: defining a custom cell object, and defining the trigger logic and display style of the cell object; setting the packaging type number to be displayed for the cell object, where the number is an integer; verifying whether the cell object is a duplicate of an existing cell object in the form factory object; and registering the non-duplicate cell objects to the form factory object.

[0022] This invention adopts a pre-implantation method, which allows direct invocation through registration ID where reference is needed. The specific code 1 below demonstrates the registration of a component, a button with ID equal to 6, and the specific definition method. This method defines a button component named lgCellBut6, defines the logic after the button is triggered in the changeEvent() method, and defines the display style of the button component in the showValue() method. The button is then registered in the lgCustomFactory (form factory) object for unified management.

[0023] Code 1, the specific definition method for the button with ID equal to 6: LGCustomCell lgCellBut6 = new LGCustomCell(new LGButton("Select")) { @Override public boolean changeEvent(Node node, PackPropertpackPropert, Object o) { LGButton lgButton = (LGButton) node; lgButton.button.setOnAction(event -> { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { SelectionDialog dialog = MaterialLibraryInterface.getInstance().createMaterialSelectionWindow(dataPool.getPdMLEntry(), regionBean.getParameter()); AbstractSelectionController controller = dialog.getController(); controller.selection.setOnAction(new SelectionHandler(controller){ @Override public void handle(ActionEvent event) { } } }); controller.selectionNotSet.setOnAction(new SelectionHandler(controller){ @Override public void handle(ActionEvent event) { } }); dialog.setVisible(true); } }); }); return true; } @Override public void showValue(Node node, PackPropert packPropert, Object o) { } @Override public Node clon() { return new LGButton("Select"); } }; This invention defines a custom table cell object LGTableCell, which inherits from the TableView object's TableCell class and implements the basic functions of the original TableCell. In the custom LGTableCell class, a data binding type start switch and a custom component factory object LGCustomFactory are defined.

[0024] This invention defines the LGCustomFactory form component factory class, which defines a unique key-value pair data structure HashMap.<Integer, LGCellInterface> `customcellMap` is a factory class where the key is a unique ID for each type of component and the value is the corresponding component object. The core method `addCustomCell` is used to register custom type components, and the `getCustomcell` method is used to retrieve custom components with a specified ID.

[0025] 2. Define row data objects and column objects in the form, and restrict the properties of each column object to preset properties.

[0026] Define TableViewEmployer objects for row data in the form, specifying the cell type and the data it contains within each object. In JavaFX, TableView is a form class object, and the column object class is TableColumn. In this invention, the specific attributes of each column in the form are defined through the generic type of TableColumn. The purpose of defining TableViewEmployer objects is to define the generic parameters of the TableColumn class; thus, when data is added to the form rows later, the data must meet the current generic requirements. In other words, it restricts the objects placed in the form columns to be of type TableViewEmployer.

[0027] 3. Define a cell data listening interface to monitor data status changes in real time, and implement specific business logic in the listening interface.

[0028] This invention defines the LGCellInterface cell data monitoring interface, which defines a cell node (Node), a method to get the return value, a method to set the current changed value (setNewValue(Object object, PackPropert property), a method to update the changed value when the cell Node data changes (changeEvent(finalT node, final PackPropert packpropertNow, final Object rowParm), a method to define the display method of the current cell Node data (showValue(T node, final PackPropert packpropertNow, ObjectnowValue), and a method to clone the cell Node style (LGCellInterface clonCellCustom() throws NoSuchMethodException).

[0029] The cell data monitoring interface defined above includes: defining monitoring parameters for the form entity class object. The member monitoring objects of the form entity class include the wrapper property PackPropert and its corresponding monitoring class object property ObjectProperty. The purpose of the monitoring object PackPropert in this invention is to trigger an event through the specific monitoring object ObjectProperty when a property in TableViewEntity changes. Then, the changeEvent() method mentioned in step 1 can detect the modification of that value, allowing specific business logic to be written based on the modified content.

[0030] Each column object implements the `setCellFactory()` listener method. The `setCellFactory()` method is used to set a custom cell factory for the form component. This mechanism allows for customization of how the content of each cell is displayed, thus enabling a more flexible and complex user interface. As shown in Code 2, the `setCellFactory()` method defines a factory method that returns a new `TableCell` instance. In this embodiment, as shown in Code 3, the `LGTableCell` class inherits from `TableCell`. As shown in Code 4, a `PackPropert` class is added to the `LGTableCell` class. This class defines an `ObjectProperty` listener class that records parameter changes, and defines properties such as cell type, cell layout base, and parameter change callback interface.

[0031] The aforementioned listening process specifically includes: data editing triggers the `bind()` method of the `ObjectProperty` class in the `LGTableCell` class. This method returns the triggered data via a callback interface using the `changeListener` parameter, or via a two-way binding listener interface using `doubleBindPropert`. Specific business logic can be written and defined within the returned callback interface.

[0032] Code 2, the code that specifically defines the application of the setCellFactory method: nameColumn.setCellFactory(new Callback <TableColumn<TableViewEmploye,Object> TableCell<TableViewEmploye, Object> >() { @Override public TableCell<TableViewEmploye, Object> call(TableColumn<TableViewEmploye, Object> param) { LGTableCell cell = new LGTableCell(lgCustomFactory); cell.setAlignment(Pos. CENTER_LEFT ); return cell; } }); Code 3, the key code defining the LGTableCell class: public class LGTableCell<S,T extends PackPropert> extends TableCell<S,T > { LGCustomFactory factory; boolean doubleBind = false; / / Whether to enable two-way binding public LGTableCell(LGCustomFactory factory ){ super(); this.factory = factory; setAlignment(Pos.CENTER);} } Code 4, the key code defining the PackPropert class: public class PackPropert <t>{ T nowValue; / / Return value type of the currently selected value int graphicType = 0; / / Packaging type Object initData; / / Initial value private ObjectProperty backValuePro = new SimpleObjectProperty("init"); private ObjectProperty cellTypePro = new SimpleObjectProperty(-1); Object rowParam; / / Row object protected ObjectProperty bindValuePro; Node cellnode; / / Cell type VBox vBox; / / Unit layout base plate ChangeListener; / / Callback interface for parameter change ObjectProperty doubleBindPropert; / / Two-way binding interface } Each column object implements the `setCellValueFactory()` listener method, which returns an `ObjectProperty` object. Code example code for the `setCellValueFactory()` listener is shown in code 5 below. The `setCellValueFactory` method is primarily used in form methods to set the cell value extractor. When the data model's properties change, the table automatically updates the displayed values, reducing the need for manual UI updates. The `ObjectProperty` class is an interface for identifying bound object properties, inheriting from Java's `Property` interface. It stores object type values ​​and allows for two-way binding between UI components and the data model. When the value of an object property changes, it can be triggered by the `setCellValueFactory()` listener method, and then the changed value can be retrieved through `ObjectProperty` for UI display.

[0033] Code 5, code for using the setCellValueFactory method: nameColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<TableViewEmploye,Object>, ObservableValue <object>>() { @Override public ObservableValue <object>call(TableColumn.CellDataFeatures<TableViewEmploye, Object> param) { return param.getValue().getPack1Pro(); } }); 4. Create the initial form, add the configured form object to the form component, and complete the filling and data loading of the custom component in the form, such as... Figure 3 As shown, an exemplary loading effect diagram is provided.

[0034] After defining the custom component, this invention creates an initial form object. In JavaFX, the form object is a TableView, which is a native basic form. After defining the form, it is necessary to define how many columns the form has and the attributes of each column; the definition method is as follows: TableView's column object TableColumn<TableViewEmploye,Object> The command `nameColumn = new TableColumn<>("");` defines a `nameColumn` object `TableColumn`, whose generic type is `TableViewEmploye`.

[0035] The present invention also needs to define a custom component initialization method addLGCell(LGCustomFactorylgCustomFactory), as shown in Code 6. This method internally implements the initialization of each custom component, including the component's listening two-way binding interface, display data interface, and style cloning interface.

[0036] Code 6 defines the custom component initialization method. LGCustomCell t6 = new LGCustomCell(new LGComboBox()) { @Override public boolean changeEvent(Node node, PackPropert packPropert,Object o) { / / Specific data status monitoring interface business return true; } @Override public void showValue(Node node, PackPropert packPropert,Object o) { LGComboBox lgbox=(LGComboBox)node; } @Override public Node clon() { return new LGComboBox(); } }; 5. Render the data in the form and monitor changes in each data point in real time.

[0037] This invention proposes a method for diversifying the population of JavaFX form components and monitoring their states. This involves creating a custom cell object, `LGCustomCell`, registering it in the `LGCustomFactory` class, initializing the form content where a TableView is needed in the JavaFX application, adding component objects using the `getItems().Add()` method of the TableView, and then using the `LGCellInterface` cell data monitoring interface to monitor data state changes in real time. The specific business logic is then implemented within this monitoring interface. In particular, the data change process and business logic are cleverly decoupled by injecting the data monitoring interface, allowing the data change event monitoring to be written into a unified interface, simplifying complex programming tasks for developers.

[0038] Obviously, those skilled in the art can make various modifications and variations to this technical solution without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this technical solution and their equivalents, this technical solution also intends to include these modifications and variations.< / object> < / object> < / t>

Claims

1. A method for diversifying the population components and listening to the state of a JavaFX form component, characterized in that, include: Define the custom components that need to be filled in the form and register them in the form factory, so that each type of component in the form factory object has a unique ID; Define row data objects and column objects in the form, and restrict the properties of each column object to preset properties; Define a cell data listening interface to monitor data status changes in real time, and implement specific business logic in the listening interface. Create an initial form, add the configured form object to the form component, and complete the filling and data loading of the custom component in the form; Render the data in the form and monitor changes in each data point in real time.

2. The method for diversifying the population components and listening to the state of JavaFX form components as described in claim 1, characterized in that, The definition specifies the custom components that need to be filled in the form and registers them in the form factory, giving each type of component in the form factory object a unique ID. Specifically, this includes: Define a custom cell object, and define the trigger logic and display style of the cell object; Set the packaging type number to be displayed for the cell object, where the number is an integer; Verify whether the cell object is a duplicate of an existing cell object in the form factory object; Register unique cell objects to the form factory object.

3. The method for diversifying the population components and listening to the state of JavaFX form components as described in claim 1, characterized in that, The specific properties of each column object in the form can be defined using generics to restrict the properties of the column objects.

4. The method for diversifying the population components and listening to the state of JavaFX form components as described in claim 1, characterized in that, The defined cell data monitoring interface includes: Define the listener parameters for the form entity class object. The member listener objects of the form entity class include the wrapper property PackPropert and its corresponding listener class object property ObjectProperty.

5. The method for diversifying the population components and listening to the state of JavaFX form components as described in claim 1, characterized in that, The real-time monitoring of data status changes through the cell data monitoring interface includes: Each column object implements the setCellFactory() listener method, which returns an LGTableCell table cell object.

6. The method for diversifying the population components and listening to the state of JavaFX form components as described in claim 1, characterized in that, The real-time monitoring of data status changes through the cell data monitoring interface also includes: Each column of objects implements the setCellValueFactory() listener method, which returns an ObjectProperty object.

7. The method for diversifying the population components and listening to the state of JavaFX form components as described in claim 1, characterized in that, When adding a form object to a form component, it can be directly invoked using the ID registered in the form factory where it needs to be referenced.