问题
I am trying to create a JCombobox and retrieving data from the MYSQL database in JUNG visualization platform. I need to know whether i can use the same method to create a JCombo box in JUNG as we created in JAVA swing? I used the following code to create and import the data from the database. But nothing gets displayed. According to the item which is selected from Jcombo box, I've to edit the jung network. Can anyone help me this?
private void mouseComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
JComboBox jcb1 = (JComboBox) evt.getSource();
try {
String query = "SELECT * FROM interr";
PreparedStatement pest = connection.prepareStatement(query);
ResultSet rs = pest.executeQuery();
while (rs.next()) {
String geneID = rs.getString("Mole1");
if (geneID.equals("")) {
jcb1.addItem("");
jcb1.setVisible(false);
} else {
jcb1.addItem(rs.getString("Mole1"));
jcb1.setVisible(true);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
String selectedItem = (String)jcb1.getSelectedItem();
if(selectedItem.equals("BRCA1")){
-----
} else {
----
}
vv.repaint();
}
来源:https://stackoverflow.com/questions/34194900/how-to-retrieve-data-from-mysql-to-combobox-in-jung-visualization