我正在开发一个 GUI,用户可以从 SYSTEM 浏览文本文件,然后当用户按下“开始”按钮时,程序读取文本文件,从其数据创建列表并应该将其添加到TableView
. 我一直坚持将列表中的数据插入到表格中。我已经按文件名创建了列名并将其添加到表中:
tblConfigurationSystemColumns.add("Parameter Name");
tblSystemColumn.stream().map((str) -> str.split("PCM")).forEachOrdered((a) -> {
tblConfigurationSystemColumns.add(a[0].trim());
});
for (int i = 0; i < tblConfigurationSystemColumns.size(); i++) {
TableColumn col = new TableColumn(tblConfigurationSystemColumns.get(i));
tableConfigurationSystem.getColumns().addAll(col);
}
来自列表的列名tblConfigurationSystemColumns
。每次使用 GUI 时,此列表可能会根据您从系统浏览的文件数进行更改。(现在让我们认为,我们有内部的2串:"column1","column2"
)
我需要将项目添加到column1
from listSysParameter
和column2
from list SysValues
。
如何按行将每个列表中的值添加到每列?如果您需要更多代码,请告诉我(让您知道,我拥有从文件创建的列表的唯一代码)。
这是我在建柱后得到的。在此之后,我需要获取每列的“参数”和“值”(如您所见)。我制作了一个从文本文件中获取“参数”的列表,以及另一个从文本文件中获取“值”的列表。
我怎样才能把每个列表放到它的列中?这是构建此列表的代码:
boolean inCESystem = false;
for (final String line : list) {
if (line.contains("CE-") && !(line.contains("CE-system-equipment-pm") || line.contains("inbound") || line.contains("outbound"))) {
inCESystem = true;
}
else if (line.trim().isEmpty()) {
inCESystem = false;
}
else if (inCESystem) {
CE_System.add(line);
}
}
boolean inCESystemInbound = false;
for (final String line : list) {
if (line.contains("CE-") && (line.contains("inbound")) ) {
inCESystemInbound = true;
}
else if (line.trim().isEmpty()) {
inCESystemInbound = false;
}
else if (inCESystemInbound) {
CE_System.add("inbound_loadlock - "+line.trim());
}
}
boolean inCESystemOutbound = false;
for (final String line : list) {
if (line.contains("CE-") && (line.contains("outbound")) ) {
inCESystemOutbound = true;
}
else if (line.trim().isEmpty()) {
inCESystemOutbound = false;
}
else if (inCESystemOutbound) {
CE_System.add("outbound_loadlock - "+line.trim());
}
}
/*
* Check the CE list to split each object per parameter and value to different lists
*/
CE_System.stream().map((str) -> str.split(",")).map((a) -> {
CE_SystemParameter.add(a[0].trim()); //Parameters
return a;
}).forEachOrdered((a) -> {
if(a.length > 1) {
CE_System_Value.add(a[1].trim()); //Values
} else {
CE_System_Value.add(""); //add blank if parameter doesn't have value
}
});
编辑 2:文本文件示例
CE-system:
No features to set for this item...
CE-system-componentmanager:
Bootstrap Parallelism ,Parallel Bootstrapping
CE-system-components:
No features to set for this item...
CE-system-components-accessmanager:
Access control enable ,disabled
Access policy prototyping ,enabled
Access user group ,enabled
Implicit roles access policy ,disabled
World access policy ,disabled
CE-system-components-eqlog:
EquipmentLog Enable ,false
EDIT 3: The table should look like this example (This example is from my code in Java SWT)
Thank you very much guys.
The data for a TableView
is held in the ObservableList
of the items
property. A TableView
is designed to hold a list of POJOs that contain various properties. Each of the properties will correspond to a TableColumn
who obtains the value of these properties using a Callback
.
Since you are browsing text files let's say you define a POJO like so:
import javafx.beans.property.LongProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.property.SimpleStringProperty;
public class TextFile {
private final StringProperty name = new SimpleStringProperty(this, "name");
public final void setName(String name) { this.name.set(name); }
public final String getName() { return name.get(); }
public final StringProperty nameProperty() { return name; }
private final LongProperty size = new SimpleLongProperty(this, "size");
public final void setSize(long size) { this.size.set(size); }
public final long getSize() { return size.get(); }
public final LongProperty sizeProperty() { return size; }
public TextFile() {}
public TextFile(String name, long size) {
setName(name);
setSize(size);
}
}
从这里你会想要一个具有for和forTableView
的TextFile
s 。要告诉如何获得正确的值,请使用适当的. 这接受 a并返回一个。如果更改将更新相应的项目。TableColumn
name
TableColumn
size
TableColumn
cellValueFactory
Callback
Callback
TableColumn.CellDataFeatures
ObservableValue
ObservableValue
TableColumn
TableCell
ObservableList<TextFile> files = ...;
TableView<TextFile> table = new TableView<>();
table.setItems(files);
TableColumn<TextFile, String> nameCol = new TableColumn<>("Name");
nameCol.setCellValueFactory(features -> features.getValue().nameProperty());
table.getColumns().add(nameCol);
TableColumn<TextFile, Number> sizeCol = new TableColumn<>("Size");
sizeCol.setCellValueFactory(features -> features.getValue().sizeProperty());
table.getColumns().add(sizeCol);
请注意,每个TextFile
infiles
都是TableView
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句