A method and apparatus for dynamic rendering of a Swing table
By combining dynamic and static style files and using the Groovy scripting language to dynamically render Swing table cells, the problem of style control and component code coupling in Java Swing table rendering is solved. This enables dynamic rendering of the table interface and flexible style switching, improving code maintainability and development efficiency.
Patent Information
- Application Number
- CN202211037867.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-26
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2042-08-26
AI Technical Summary
In existing Java Swing-based applications, the style control code and component code are highly coupled when rendering table components, resulting in low flexibility and maintainability, and making it impossible to achieve dynamic rendering of the table interface.
This approach combines dynamic and static style files. Dynamic style files are written using the Groovy dynamic scripting language to separate style control code from component code. Swing table cells are dynamically rendered, and cell components are returned using the Java dynamic renderer interface and Groovy script.
It implements dynamic rendering of Swing tables, allowing for dynamic style switching without compilation, which improves the flexibility of style control, reduces development time, and enhances code maintainability and decoupling of the interface layer.
Smart Images

Figure CN115344242B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a Swing table dynamic rendering method and device. BACKGROUND
[0002] At present, when the application program developed based on Java Swing renders the table component, firstly, the method for obtaining the table cell renderer interface in the table component is used to return the cell renderer interface of the specified row and column, and then the renderer interface returns each cell component, and the table UI is formed by the multiple cell components.
[0003] The table cell renderer interface is provided by the Java Swing development platform, which returns the cell component of the corresponding row and column, and the Java platform provides the default renderer implementation, which defines each cell component as a label component to realize the default table UI.
[0004] If the style of the table needs to be modified, the renderer of the corresponding cell needs to be modified, and currently, the modification can only take effect after the Java source code is compiled into class, the flexibility and maintainability are low, and the style control code and the table component code are highly coupled. In the actual application development process, the customized and personalized requirements are often proposed, and the change of the user requirements will cause the recompilation of the Java application, and the dynamic rendering of the table interface cannot be realized.
[0005] Therefore, the present application provides a table dynamic rendering technology to meet the current requirements. SUMMARY
[0006] The present application provides a Swing table dynamic rendering method and device, which filters and renders the cell in the table to be rendered based on the Swing table, the dynamic style file and the static style file, separates the style control code and the component code, and meets the current table rendering requirements.
[0007] In the first aspect, the present application provides a Swing table dynamic rendering method, which comprises the following steps:
[0008] Based on the table to be rendered, the corresponding dynamic style file and the static style file are obtained;
[0009] The dynamic style file is executed to filter and obtain the cell component in the table to be rendered which meets the preset filtering condition, which is recorded as the cell component to be rendered;
[0010] Based on the row and column information of the cell component to be rendered and the static style file, the corresponding table style information is configured to the cell component to be rendered;
[0011] A1, define a Java dynamic renderer interface, the Java dynamic renderer interface configures a dynamic renderer interface method, which is used to return a cell component corresponding to a cell;
[0012] A2, write a dynamic style file using a Groovy dynamic script language:
[0013] A2.1, configure a unique name of the dynamic style file;
[0014] A2.2, the dynamic style file implements the dynamic renderer interface, rewrites the dynamic renderer interface method, and returns the cell component;
[0015] A3, according to the style table name matching A2.1 unique name to find the corresponding name of the Groovy script;
[0016] A4, if the corresponding script is found, the A2.2 method in the Groovy script is run to return the cell component by using the fully compatible characteristics of the Groovy language and the Java language, and the dynamic rendering of the table style based on the table data model is realized;
[0017] A5, if the corresponding script is not found, a default table renderer is used to return the corresponding cell component; wherein,
[0018] The static style file is used to store row and column information and corresponding table style information;
[0019] The style table name is the Name attribute in the table;
[0020] The table data model is to specify the content of a cell;
[0021] The table style is composed of N cell styles;
[0022] The cell style includes background color and font.
[0023] Specifically, the format of the table to be rendered in the method is consistent with the format of the preset style table; wherein,
[0024] The style table is obtained based on the original Java Swing table encapsulation;
[0025] The style table is configured with a custom renderer, which is used to configure the corresponding table style information to the cell component to be rendered.
[0026] Specifically, the execution of the dynamic style file, filtering to obtain the cell component in the table to be rendered that meets the preset filtering condition, denoted as the cell component to be rendered, includes the following steps:
[0027] The dynamic style file is executed to filter the cell component of the data model meeting the preset filtering condition as the cell component to be rendered according to the row and column information of each cell component in the table to be rendered and the corresponding data model, wherein
[0028] The data model is used to record the parameter data information of the cell component.
[0029] Specifically, the corresponding table style information is configured to the cell component to be rendered based on the row and column information of the cell component to be rendered and the static style file, including the following steps:
[0030] The data attribute of the data model of the cell component to be rendered is obtained based on the row and column information of the cell component to be rendered.
[0031] The corresponding style information is obtained from the static style file based on the data attribute of the data model of the cell component to be rendered.
[0032] The corresponding table style information is configured to the cell component to be rendered based on the style information, wherein
[0033] The static style file records the data attribute of the data model of the cell component and the corresponding style information.
[0034] Specifically, the corresponding table style information is configured to the cell component to be rendered based on the row and column information of the cell component to be rendered and the static style file, including the following steps:
[0035] The corresponding style information is obtained from the static style file based on the row and column information of the cell component to be rendered.
[0036] The corresponding table style information is configured to the cell component to be rendered based on the style information, wherein
[0037] The static style file records the row and column information of the cell component and the corresponding style information.
[0038] Specifically, the style information includes background color, font or font size.
[0039] Specifically, the dynamic style file is written in Groovy dynamic script language.
[0040] Specifically, the dynamic style file has a unique name.
[0041] Further, the method further includes the following steps:
[0042] Based on the preset row and column information, the table to be rendered is searched to obtain a corresponding cell component, denoted as a cell component to be rendered.
[0043] In a second aspect, the application provides a device for dynamically rendering a Swing table, the device comprising:
[0044] a style file obtaining module configured to obtain a corresponding dynamic style file and a static style file based on a table to be rendered;
[0045] a dynamic style file executing module configured to execute the dynamic style file to filter a cell component to be rendered in the table to be rendered that meets a preset filtering condition, denoted as a cell component to be rendered;
[0046] a static style file executing module configured to configure corresponding table style information to the cell component to be rendered based on row and column information of the cell component to be rendered and the static style file;
[0047] a cell component obtaining module configured to execute the following procedure:
[0048] A1, defining a Java dynamic renderer interface, the Java dynamic renderer interface configuring a dynamic renderer interface method for returning a cell component of a corresponding cell;
[0049] A2, using a Groovy dynamic script language to write a dynamic style file:
[0050] A2.1, configuring a unique name of the dynamic style file;
[0051] A2.2, the dynamic style file implementing the dynamic renderer interface, rewriting the dynamic renderer interface method, and returning the cell component;
[0052] A3, according to the style table name matching A2.1 unique name to find the Groovy script of the corresponding name;
[0053] A4, if the corresponding script is found, using the fully compatible characteristics of the Groovy language and the Java language to run the A2.2 method in the Groovy script to return the cell component, and realizing the dynamic rendering of the table style based on the table data model;
[0054] A5, if the corresponding script is not found, using a default table renderer to return the corresponding cell component; wherein,
[0055] the static style file is used to store row and column information and corresponding table style information;
[0056] the style table name is a Name attribute in the table;
[0057] The table data model is to specify the content of a cell;
[0058] The table style is composed of N cell styles;
[0059] The cell style includes background color and font.
[0060] The technical scheme provided by the application has the beneficial effects including:
[0061] The application filters and renders the cells in the table to be rendered based on the Swing table, the dynamic style file and the static image file, separates the style control code and the component code, and meets the current table rendering requirements. BRIEF DESCRIPTION OF DRAWINGS
[0062] In order to more clearly illustrate the technical solutions in the embodiments of the application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the application, and other drawings can be obtained by those skilled in the art without creative labor.
[0063] Fig. 1 The step flow chart of the dynamic rendering method of the Swing table provided in the embodiments of the application;
[0064] Fig. 2 The principle flow chart of the dynamic rendering method of the Swing table provided in the embodiments of the application;
[0065] Fig. 3 The implementation flow chart of the dynamic rendering method of the Swing table provided in the embodiments of the application. DETAILED DESCRIPTION
[0066] In order to make the purpose, technical scheme and advantages of the embodiments of the application more clear, the technical scheme in the embodiments of the application will be described clearly and completely in combination with the drawings in the embodiments of the application. Obviously, the described embodiments are part of the embodiments of the application, not all the embodiments. Based on the embodiments in the application, all other embodiments obtained by those skilled in the art without creative labor belong to the scope of protection of the application.
[0067] The embodiments of the application will be further described in detail below in combination with the drawings.
[0068] The embodiment of the application provides a dynamic rendering method and device of a Swing table, based on a Swing table, a dynamic style file and a static style file, a cell in a table to be rendered is screened and corresponding rendering work is performed, separation of style control code and component code is realized, and current table rendering requirements are met.
[0069] To achieve the above technical effects, the general idea of the application is as follows:
[0070] A dynamic rendering method of a Swing table, the method comprising the following steps:
[0071] S1, based on a table to be rendered, obtaining a corresponding dynamic style file and a static style file;
[0072] S2, executing the dynamic style file, screening a cell component in the table to be rendered that meets a preset screening condition, and marking the cell component as a cell component to be rendered;
[0073] S3, based on row and column information of the cell component to be rendered and the static style file, configuring corresponding table style information to the cell component to be rendered; wherein,
[0074] The static style file is used for storing the row and column information and the corresponding table style information.
[0075] The embodiment of the application is further described in detail below with reference to the accompanying drawings.
[0076] In a first aspect, referring to Figs. 1-3 The embodiment of the application provides a dynamic rendering method of a Swing table, the method comprising the following steps:
[0077] S1, based on a table to be rendered, obtaining a corresponding dynamic style file and a static style file;
[0078] S2, executing the dynamic style file, screening a cell component in the table to be rendered that meets a preset screening condition, and marking the cell component as a cell component to be rendered;
[0079] S3, based on row and column information of the cell component to be rendered and the static style file, configuring corresponding table style information to the cell component to be rendered; wherein,
[0080] The static style file is used for storing the row and column information and the corresponding table style information.
[0081] In the embodiment of the application, based on a Swing table, a dynamic style file and a static style file, a cell in a table to be rendered is screened and corresponding rendering work is performed, separation of style control code and component code is realized, and current table rendering requirements are met.
[0082] The technical scheme of the embodiment of the application realizes dynamic rendering of a table UI by combining a dynamic style file and a static style file, and can dynamically realize switching of styles without compiling, and style control is more flexible.
[0083] Development time is reduced, static style writing is simpler, and different styles can be referenced by multiple tables.
[0084] The maintainability of code is improved, the interface layer code does not need to pay attention to the details of the renderer, and the view layer and the renderer code are decoupled.
[0085] Specifically, the format of the table to be rendered in the method is consistent with the format of the preset style table.
[0086] The style table is obtained based on an original Java Swing table encapsulation.
[0087] The style table is configured with a custom renderer, and the custom renderer is used to configure corresponding table style information to the cell component to be rendered.
[0088] It should be noted that, by the inheritance feature of Java, the style table rewrites the method of obtaining the renderer in the Swing component JTabel, thereby returning the custom renderer.
[0089] In addition, the custom renderer implements the cell renderer interface, returns the specified cell component, and the renderer is internally executed by a preset dynamic script controller to return the corresponding cell component. A preset static script controller is executed to set the style of the cell component, and a processed cell component is returned. Wherein,
[0090] In the Swing table component, each cell presents a Swing component in nature. The embodiment of the application creates a Swing component of the corresponding cell in the dynamic script file. After creation, the style of the Swing component can be processed by the static script controller, and finally returned to the style table component for interface UI drawing.
[0091] The cell component refers to each cell in the Swing table, which specifies the display content and presentation method of the cell.
[0092] During the drawing process of the Swing table, the final table UI is actually formed by the drawing of multiple cell components.
[0093] Specifically, the execution of the dynamic style file, the filtering of the cell component in the table to be rendered that meets the preset filtering condition, and the recording of the cell component to be rendered include the following steps:
[0094] The dynamic style file is executed to filter the cell component of the data model meeting the preset filtering condition as the cell component to be rendered according to the row and column information of each cell component in the table to be rendered and the corresponding data model.
[0095] The data model is used to record the parameter data information of the cell component.
[0096] Specifically, the corresponding table style information is configured to the cell component to be rendered based on the row and column information of the cell component to be rendered and the static style file, including the following steps:
[0097] The data attribute of the data model of the cell component to be rendered is obtained based on the row and column information of the cell component to be rendered.
[0098] The corresponding style information is obtained from the static style file based on the data attribute of the data model of the cell component to be rendered.
[0099] The corresponding table style information is configured to the cell component to be rendered based on the style information.
[0100] The static style file records the data attribute of the data model of the cell component and the corresponding style information.
[0101] Specifically, the corresponding table style information is configured to the cell component to be rendered based on the row and column information of the cell component to be rendered and the static style file, including the following steps:
[0102] The corresponding style information is obtained from the static style file based on the row and column information of the cell component to be rendered.
[0103] The corresponding table style information is configured to the cell component to be rendered based on the style information.
[0104] The static style file records the row and column information of the cell component and the corresponding style information.
[0105] In the embodiment of the application, the style information includes background color, font, font size and other attribute information related to the UI layer.
[0106] Specifically, the dynamic style file is written in Groovy dynamic script language.
[0107] Specifically, the dynamic style file has a unique name.
[0108] Further, the method further includes the following steps:
[0109] Based on the preset row and column information, the table to be rendered is searched to obtain a corresponding cell component, denoted as a to-be-rendered cell component;
[0110] Further, based on the row and column information of the to-be-rendered cell component and the static style file, corresponding table style information is configured to the to-be-rendered cell component.
[0111] The related technologies of the static script controller and the static script file are described in detail as follows:
[0112] The static script file is defined, which can be placed in a specified directory of a Java application. The static script file contains specified row and column information and table style information (such as background color, font, etc.). The table style information in the static script file is parsed according to the row and column information. After the cell components in the table to be rendered that meet the preset filtering condition are filtered and the corresponding cell components are returned, the style of the returned cell components is modified according to the parsed table style information, and the corresponding cell components are returned after the modification.
[0113] Based on the above technical content, the detailed design steps of the static script file are as follows:
[0114] The dynamic script file is defined, which can be placed in a specified directory of a Java application. The row and column information and table objects of the table are used as parameters. The data model of any cell can be obtained in the table object. The corresponding cell component is returned after the dynamic script is executed according to the data model as a condition. The setting of the cell style is realized in the parsing process, and the corresponding cell component is returned.
[0115] In the Swing table, the data model refers to TableModel, which describes the content returned in any row and column of the cell. The data model here refers to the content in the cell. For example, the first column of the table corresponds to height, and the first row of data is 1.8. Therefore, the data model of the first row and the first column of the cell is 1.8.
[0116] The data model refers to the content returned in the specified row and column of the table model, that is, the parameter data information stored in the cell corresponding to the specified row and column. The cell component refers to the Swing component in the specified row and column of the Swing table. The content of the actual cell component is displayed according to the data in the specified row and column.
[0117] The technical scheme of the embodiment of the application provides a method for obtaining a cell component, that is, constructing a Swing component, setting a style of the Swing component, and returning a corresponding cell component. Table style information needs to be set according to different styles of the component. If it is a text box, the attribute can be referred to in the static style text. If it is a check box or a drop-down box, the attribute needs to be set according to the actual scene.
[0118] The detailed design steps are as follows:
[0119] A1, define a Java dynamic renderer interface, the interface only has a method for returning a cell component corresponding to a cell, and the method is as follows:
[0120] Component getDynamicRenderCom(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column);
[0121] Return value:
[0122] Component - the returned cell component, which can set the attribute according to the row and column information and the value of the table
[0123] Parameter:
[0124] table - the current table instance
[0125] value - the value of the current cell
[0126] isSelected - whether the current cell is selected
[0127] hasFocus - whether the current cell has focus
[0128] row - the row index of the current cell
[0129] column - the column index of the current cell.
[0130] A2, a dynamic style file is written by using a Groovy dynamic script language. The Groovy script and the Java language are compatible, and the script can be directly run in the Java program. The script implements the dynamic renderer interface, and specifically includes the following information:
[0131] A2.1, configure the unique name of the dynamic style file.
[0132] A2.2, the dynamic style file implements the dynamic renderer interface, rewrites the dynamic renderer interface method, and returns the cell component.
[0133] Example:
[0134] If you want to set the background color of rows with math scores greater than 80 in the score table to green, you need to define a score.groovy dynamic script file. The script class implements the dynamic renderer interface defined in S3.1. The method can return a label component through the default renderer, then retrieve the score value of the corresponding row in the math score column of the table, and set the background color of the label component to green when the score value is greater than 80, and then return the label component.
[0135] A3. Match the unique name in A2.1 to find the corresponding Groovy script; where,
[0136] The stylesheet name refers to the Name property in the table, which needs to be set in advance. Here, it matches the table name with the Groovy script file name.
[0137] For example, if the table name is set to "Student", then the corresponding "Student..groovy" script needs to be searched for in the specified directory for matching.
[0138] Furthermore, Groovy is a dynamic language used in the Java Virtual Machine, allowing it to interoperate with Java. Groovy scripts load source files via GroovyClassLoader and directly load binary streams into memory. In Java, methods within the Groovy script can be called to return specified cell components.
[0139] A4. If a corresponding script is found, leverage the full compatibility between Groovy and Java languages to run method A2.2 in the Groovy script, returning the cell component to achieve dynamic rendering of the table style based on the table data model; where,
[0140] The table data model refers to the TableModel mentioned above. The data model here can be understood as the content of a specified cell. After the cell component is returned here, multiple cell components are combined to form the table UI.
[0141] Table styles can be understood as a collection of many cell styles, such as background color, font, etc., which will be mentioned later.
[0142] A5. If no corresponding script is found, the default table renderer will be used to return the corresponding cell component.
[0143] Based on the above technical content, the detailed design steps for static script files are as follows:
[0144] B1, Global.json is defined by JSON static script, and the definition and parsing rules can be defined according to Java Swing related styles. Some content definitions are as follows:
[0145] [{"name": "style name", "background": "background color", "Foreground": "foreground color", "font": {
[0146] "name": font name,
[0147] "size": font size,
[0148] "style": font style
[0149] },
[0150] "border": {
[0151] "top": top margin,
[0152] "left": left margin,
[0153] "bottom": bottom margin,
[0154] "right": right margin
[0155] },
[0156] "verticalAlignment": "vertical alignment",
[0157] "horizontalAlignment": "horizontal alignment"}]
[0158] Background -> Value range: constant defined in Color class in Java or rgb value, such as Color.white / [255, 255, 255]
[0159] Foreground -> Value range: constant defined in Color class in Java or rgb value, such as Color.white / [255, 255, 255]
[0160] Font ->
[0161] name -> Value range: font name, such as "Songti", "Times New Roman", "Microsoft Yahei", etc.
[0162] size -> Value range: positive integer;
[0163] The value range for style is 0 (normal), 1 (bold), 2 (italic), and (bold italic).
[0164] border ->
[0165] The value of top is a positive integer.
[0166] left -> The range of values is positive integers;
[0167] bottom -> The value range is positive integers;
[0168] The value of right is a positive integer.
[0169] verticalAlignment -> Values can be TOP, CENTER, BOTTOM:
[0170] horizontalAlignment -> Values range from LEFT, CENTER, RIGHT, LEADING:
[0171] Example:
[0172] [{
[0173] "name": "oddRender",
[0174] "background": "white",
[0175] "Foreground": "white",
[0176] "font": {
[0177] "name": "SimSun"
[0178] "size": 24,
[0179] "style": 1
[0180] },
[0181] border: {
[0182] "top": 10,
[0183] "left": 10,
[0184] "bottom": 10,
[0185] "right": 10,
[0186] },
[0187] "verticalAlignment": "center",
[0188] "horizontalAlignment": "center"
[0189] }]
[0190] B2. Define the style file for the style table, associate it with global styles, and define it as follows:
[0191] {
[0192] "Table Name": [
[0193] {
[0194] "col": table column.
[0195] "row": "table row"
[0196] "ref": "The name defined in the global style being referenced"
[0197] } ]
[0199] }
[0200] col -> The range of values is positive integers;
[0201] row -> The value range is Odd, Even, and positive integers;
[0202] ref -> takes the name of the style in Global.json.
[0203] For example:
[0204] To display the name column in the score table using a zebra stripe format, you can define the odd-numbered rows using the corresponding oddRender style, as follows:
[0205] {
[0206] "score": [
[0207] {
[0208] "col": 1,
[0209] "row" : "Odd",
[0210] "ref" : "oddRender"
[0211] } ]
[0213] }
[0214] B3. Based on the style table name, match the table name defined in step B2 to find the corresponding static style file.
[0215] B4. If the corresponding style file cannot be found, return.
[0216] B5. If a corresponding style file is found, then look for the corresponding ref attribute in the static style file, and match the name attribute defined in step B1 based on that attribute.
[0217] B6. If no matching name is found, return.
[0218] B7. If the name attribute is matched, the background color, font, and other attributes defined in step B1 will be used as the style of the cell and set in the corresponding cell component.
[0219] It should be noted that the static style definition and the Java Swing table mapping are as follows:
[0220] "background":"white" ->JLabel.setBackground(Color.white);
[0221] "Foreground":"white" ->JLabel.setForeground(Color.white);
[0222] "font": {"name": "SimSun","size": 24, "style": 1}->JLabel.setFont(newFont("SimSun", 1, 24));
[0223] "border": {"top": 10, "left": 10, "bottom": 10, "right": 10} ->
[0224] JLabel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
[0225] "verticalAlignment":"CENTER" ->JLabel.setVerticalAlignment(SwingConstants.CENTER);
[0226] "horizontalAlignment":"CENTER" ->JLabel.setHorizontalAlignment(SwingConstants. CENTER).
[0227] Based on the technical solutions of the embodiments of the present application, an implementation process is given, which is specifically as follows:
[0228] In step M1, the custom Swing table inherits from the style table, and the table name is set as test;
[0229] In step M2, the corresponding dynamic style file (test.groovy) is found according to the table name test in the specified script directory;
[0230] In step M3, after step M2 ends, if the corresponding dynamic style file is found, step M5 is started; if the dynamic style file with the corresponding name is not found, step M4 is started;
[0231] In step M4, the default cell component of the table is returned;
[0232] In step M5, the custom cell component is returned according to the dynamic style file;
[0233] In step M6, the cell component returned in step M5 is returned.
[0234] In step M7, the corresponding static style file (test.json) is found according to the table name test in the specified script directory;
[0235] In step M8, after step M7 ends, if the corresponding static style file is found, step M9 is started; if the static style file with the corresponding name is not found, step M10 is directly entered;
[0236] In step M9, the cell component related properties of step M6 are set through the static style file definition, and the specific setting method refers to the related technical content of the static script controller described above;
[0237] In step M10, the table UI is formed by the plurality of cell components.
[0238] In the second aspect, based on the dynamic rendering method of the Swing table mentioned in the first aspect, a dynamic rendering device of the Swing table is provided, and the device comprises:
[0239] The style file acquisition module is configured to obtain the corresponding dynamic style file and the static style file based on the table to be rendered;
[0240] a dynamic style file execution module, configured to execute the dynamic style file, and to filter a cell component group in the to-be-rendered table that meets a preset filtering condition, denoted as a to-be-rendered cell component;
[0241] a static style file execution module, configured to configure corresponding table style information to the to-be-rendered cell component based on row and column information of the to-be-rendered cell component and the static style file; and
[0242] The static style file is configured to store row and column information and corresponding table style information.
[0243] In the embodiments of the present application, the cell in the to-be-rendered table is filtered and rendered based on the Swing table, the dynamic style file and the static style file, the separation of the style control code and the component code is realized, and the current table rendering requirement is met.
[0244] The technical scheme of the embodiments of the present application realizes the dynamic rendering of the table UI by combining the dynamic style file and the static style file, the switching of the style can be dynamically realized without compiling, and the style control is more flexible;
[0245] The development time is reduced, the static style is easier to write, and different styles can be referenced by multiple tables;
[0246] The maintainability of the code is improved, the interface layer code does not need to pay attention to the details of the renderer, and the view layer and the renderer code are decoupled.
[0247] Specifically, the format of the to-be-rendered table in the embodiments of the present application is consistent with the format of the preset style table; wherein,
[0248] The style table is obtained based on an original Java Swing table encapsulation;
[0249] The style table is configured with a custom renderer, and the custom renderer is configured to configure corresponding table style information to the to-be-rendered cell component.
[0250] Specifically, the dynamic style file execution module executes the dynamic style file, and filters the cell component that meets the preset filtering condition in the data model based on the row and column information of each cell component in the to-be-rendered table and the corresponding data model, denoted as a to-be-rendered cell component; wherein,
[0251] The data model is configured to record the parameter data information of the cell component.
[0252] Specifically, the static style file execution module is further configured to perform the following operations:
[0253] obtaining data attributes of a data model of the to-be-rendered cell component based on the row and column information of the to-be-rendered cell component;
[0254] obtaining corresponding style information from the static style file based on the data attributes of the data model of the to-be-rendered cell component;
[0255] configuring corresponding table style information to the to-be-rendered cell component based on the style information, and
[0256] The static style file records data attributes of a data model of a cell component and corresponding style information.
[0257] Further, the static style file execution module is further configured to perform the following operations:
[0258] The configuring of the corresponding table style information to the to-be-rendered cell component based on the row and column information of the to-be-rendered cell component and the static style file comprises the following steps:
[0259] obtaining corresponding style information from the static style file based on the row and column information of the to-be-rendered cell component;
[0260] configuring corresponding table style information to the to-be-rendered cell component based on the style information, and
[0261] The static style file records row and column information of a cell component and corresponding style information.
[0262] Specifically, the style information includes background color, font, or font size.
[0263] Specifically, the dynamic style file is written in a Groovy dynamic script language.
[0264] Specifically, the dynamic style file has a unique name.
[0265] Further, the static style file execution module is further configured to find the to-be-rendered table based on preset row and column information, and obtain corresponding cell components, denoted as to-be-rendered cell components.
[0266] It has to be noted that, in the present application, the terms "first", "second", etc. are used merely to distinguish one entity or action from another entity or action, without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises", "comprising", or any other variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the presence of additional identical elements in the process, method, article, or apparatus that comprises the element.
[0267] The foregoing detailed description has set forth various embodiments of the application via the use of specific terminology. However, embodiments thereof can be practiced without the specific details ("every" embodiment) set forth above. In general, the terms used are intended to be illustrative and not restrictive, and it will be apparent to those skilled in the art that other variations and modifications of the application can be made without departing from the spirit or scope of the application. Accordingly, the scope of the application should be determined not with the foregoing description alone, but instead should be determined in accordance with the appended claims and equivalents thereof.
Claims
1. A method for dynamically rendering Swing tables, characterized in that, The method includes the following steps: Based on the table to be rendered, obtain the corresponding dynamic style file and static style file; Execute the dynamic style file to filter and obtain cell components in the table to be rendered that meet the preset filtering conditions, and record them as cell components to be rendered. Based on the row and column information of the cell component to be rendered and the static style file, configure the corresponding table style information to the cell component to be rendered; A1. Define a Java dynamic renderer interface. The Java dynamic renderer interface configures a dynamic renderer interface method, which is used to return the cell component of the corresponding cell. A2. Use the Groovy dynamic scripting language to write dynamic style files: A2.1 Configure a unique name for the dynamic style file; A2.2 The dynamic style file implements the dynamic renderer interface, overrides the dynamic renderer interface methods, and returns a cell component; A3. Match the unique name in A2.1 to find the corresponding Groovy script; A4. If the corresponding script is found, take advantage of the full compatibility between Groovy and Java languages, run the A2.2 method in the Groovy script to return the cell component, and realize the dynamic rendering of the table style based on the table data model. A5. If no corresponding script is found, the default table renderer will be used to return the corresponding cell component; where, The static style file is used to store row and column information and corresponding table style information; The stylesheet name is the Name attribute in the table; A tabular data model specifies the content of a cell; A table style is composed of multiple cell styles; Cell styles include background color and font.
2. The dynamic rendering method for Swing tables as described in claim 1, characterized in that: The format of the tables to be rendered in the method is consistent with the format of the preset style tables; wherein, The style table is obtained by encapsulating the original Java Swing table; The style table is configured with a custom renderer, which is used to configure the corresponding table style information to the cell component to be rendered.
3. The dynamic rendering method for Swing tables as described in claim 1, characterized in that, The process of executing the dynamic style file and filtering out cell components in the table to be rendered that meet preset filtering conditions, denoted as the cell components to be rendered, includes the following steps: The dynamic style file is executed, and based on the row and column information of each cell component in the table to be rendered and the corresponding data model, cell components that meet the preset filtering conditions are selected and recorded as cell components to be rendered; wherein, The data model is used to record the parameter data information recorded by the cell component.
4. The dynamic rendering method for Swing tables as described in claim 1, characterized in that, The step of configuring the corresponding table style information for the cell component to be rendered based on the row and column information of the cell component to be rendered and the static style file includes the following steps: Based on the row and column information of the cell component to be rendered, obtain the data attributes of the data model of the cell component to be rendered; Based on the data attributes of the data model of the cell component to be rendered, the corresponding style information is obtained in the static style file; Based on the style information, the corresponding table style information is configured for the cell component to be rendered; wherein... The static style file records the data attributes of the cell component's data model and the corresponding style information.
5. The dynamic rendering method for Swing tables as described in claim 1, characterized in that, The step of configuring the corresponding table style information for the cell component to be rendered based on the row and column information of the cell component to be rendered and the static style file includes the following steps: Based on the row and column information of the cell component to be rendered, the corresponding style information is obtained from the static style file; Based on the style information, the corresponding table style information is configured for the cell component to be rendered; wherein... The static style file records the row and column information of the cell component and the corresponding style information.
6. The dynamic rendering method for Swing tables as described in claim 1, characterized in that, The method further includes the following steps: Based on the preset row and column information, the table to be rendered is searched to obtain the corresponding cell component, which is denoted as the cell component to be rendered.
7. A dynamic rendering device for Swing tables, characterized in that, The device includes: The style file acquisition module is used to obtain the corresponding dynamic style file and static style file based on the table to be rendered; A dynamic style file execution module is used to execute the dynamic style file and filter out cell components in the table to be rendered that meet the preset filtering conditions, denoted as cell components to be rendered. A static style file execution module is used to configure corresponding table style information for the cell component to be rendered based on the row and column information of the cell component to be rendered and the static style file. The cell component retrieval module is used to perform the following process: A1. Define a Java dynamic renderer interface. The Java dynamic renderer interface configures a dynamic renderer interface method, which is used to return the cell component of the corresponding cell. A2. Use the Groovy dynamic scripting language to write dynamic style files: A2.1 Configure a unique name for the dynamic style file; A2.2 The dynamic style file implements the dynamic renderer interface, overrides the dynamic renderer interface methods, and returns a cell component; A3. Match the unique name in A2.1 to find the corresponding Groovy script; A4. If the corresponding script is found, take advantage of the full compatibility between Groovy and Java languages, run the A2.2 method in the Groovy script to return the cell component, and realize the dynamic rendering of the table style based on the table data model. A5. If no corresponding script is found, the default table renderer will be used to return the corresponding cell component; where, The static style file is used to store row and column information and corresponding table style information; The stylesheet name is the Name attribute in the table; A tabular data model specifies the content of a cell; A table style is composed of multiple cell styles; Cell styles include background color and font.
Citation Information
Cited By
Table cell style rendering method based on node attribute extension
CN122065781A
A table cell style rendering method based on node attribute extension
CN122065781B