我開發了一款使用neo4j創建本體的軟件。建立本體之後,我開始將200萬行數據集映射到它,這需要大約20分鐘才能完成。因此,我希望添加一個顯示流程執行的JFrame。下面的代碼在開始時創建JFrame,然後開始映射數據集。不過,我可以在執行過程中看到JFrame,但其映射完成後,其組件出現在JFrame內部。我已經讀過這個問題,可能是由於缺少圍繞代碼的線程。任何人都可以幫助我解決這個問題嗎?直到數據集映射結束,我才能看到JFrame組件。爲什麼?
void createGraphDataset(String [][] choices , final ArrayList<String[]> DatabaseFile, GraphDatabaseService BORO_DB){
JFrame converterFrame = new JFrame();
converterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
converterFrame.setBounds(100, 100, 650, 288);
JPanel contentPane = new JPanel();
contentPane.setLayout(null);
contentPane.setVisible(true);
converterFrame.getContentPane().add(contentPane);
JPanel panelNeo1 = new JPanel();
panelNeo1.setBounds(6, 6, 638, 254);
panelNeo1.setVisible(true);
contentPane.add(panelNeo1);
panelNeo1.setLayout(null);
JLabel labelNeo1 = new JLabel("CSV BORO Converter");
labelNeo1.setBounds(16, 19, 260, 37);
panelNeo1.add(labelNeo1);
labelNeo1.setVisible(true);
JPanel panelNeo2 = new JPanel();
panelNeo2.setBounds(16, 60, 605, 167);
panelNeo1.add(panelNeo2);
panelNeo2.setLayout(null);
panelNeo2.setVisible(true);
/*
JProgressBar progressBar = new JProgressBar();
progressBar.setBounds(27, 89, 547, 20);
panelNeo2.add(progressBar);
panelNeo2.setVisible(true);
*/
JLabel labelNeo2 = new JLabel(" Processing: Number of row");
labelNeo2.setOpaque(true);
labelNeo2.setBounds(28, 36, 184, 20);
panelNeo2.add(labelNeo2);
labelNeo2.setVisible(true);
JLabel labelNeo3 = new JLabel("");
labelNeo3.setBounds(212, 36, 76, 20);
panelNeo2.add(labelNeo3);
labelNeo3.setVisible(true);
JLabel labelNeo4 = new JLabel();
labelNeo4.setText(String.valueOf(DatabaseFile.size()));
labelNeo4.setBounds(311, 36, 70, 20);
panelNeo2.add(labelNeo4);
labelNeo4.setVisible(true);
JLabel labelNeo6 = new JLabel("of");
labelNeo6.setBounds(288, 36, 23, 20);
panelNeo2.add(labelNeo6);
labelNeo6.setVisible(true);
converterFrame.setVisible(true);
TopNode= new Node [DatabaseFile.get(0).length];
//Create TopNodes
Transaction tx0 = BORO_DB.beginTx();
try{
for(int u =0; u<DatabaseFile.get(0).length;u++){
TopNode[u]=BORO_DB.createNode();
TopNode[u].setProperty("name", choices[u][0]);
}
tx0.success();
}
finally{
tx0.finish();
}
//Create the database
for(int i =0; i<DatabaseFile.size();i++){
Transaction tx2 = BORO_DB.beginTx();
try
{
// Nodes for each row
Node []graphNode= new Node [DatabaseFile.get(i).length];
// Relationships for each row ingoing
Relationship [] graphRelOn = new Relationship [DatabaseFile.get(i).length-1];
// Relationships for each row outgoing
Relationship [] graphRelOut = new Relationship [DatabaseFile.get(i).length-1];
//Relationship to TopNode ingoing
Relationship TopNodeRelIn[]=new Relationship [DatabaseFile.get(i).length];
//Creates Nodes for row and relationship to TopNode
for(int j=0; j<DatabaseFile.get(i).length;j++){
//Stores Database values
String []ValuesRow =DatabaseFile.get(i);
//Creates nodes for 1 row
graphNode[j] = BORO_DB.createNode();
graphNode[j].setProperty("name", ValuesRow[j]);
//From row to TopNode Relationship (enter)
TopNodeRelIn[j]=graphNode[j].createRelationshipTo(TopNode[j], RelTypes.typeInstances);
TopNodeRelIn[j].setProperty("relationship-type", "typeInstances");
}
//Creates Relationships
for(int k=0; k<(DatabaseFile.get(i).length)-1;k++){
//Between same elements of the same row (left to right)
graphRelOn[k]=graphNode[k].createRelationshipTo(graphNode[k+1], RelTypes.relatesTo);
graphRelOn[k].setProperty("relationship-type", "relatesTo");
//Between same elements of the same row (right to left)
graphRelOut[k]=graphNode[(DatabaseFile.get(i).length)-1].createRelationshipTo(graphNode[(DatabaseFile.get(i).length)-(2+k)], RelTypes.relatesTo);
graphRelOut[k].setProperty("relationship-type", "relatesTo");
}
tx2.success();
}
finally
{
tx2.finish();
}
}
}
這個問題缺少兩個重要的事情,1)SSCCE,2)AWT/Swing的JComponents被指定爲可重複使用的,然後是否有任何重新安裝新的無論在運行時 – mKorbel
你不需要setVisible(true)框架內的每一個組件。只是JFrame本身。 – Kayaman
@mKorbel 1)我很抱歉,我知道它有點長,但我不知道問題出在哪裏,什麼是重要的,什麼不重要(我是初學者)。這就是爲什麼我粘貼了整個代碼。 2)我不明白答案 – QGA