0

I have developed a MySQL database with 3 different columns. Among three columns, I used 2 columns to develop a network using JUNG. Now if I place a mouse over the vertex, the corresponding information from the third column should be displayed. I have tried with the following code with the help of setVertexToolTipTransformer. But nothing is displayed as an answer.

vv.setVertexToolTipTransformer(new Transformer<String, String>() {
        public String transform(String v) {
            try {

                 String bb = "SELECT * FROM interr'";
                Statement pest = connection.createStatement();
                ResultSet v1 = pest.executeQuery(bb);   
                while(v1.next())
                    v= v1.getString("Pubchem_ID");

                return "PUBMED:"+v.toString();
            }
        catch (Exception e1) {
            JOptionPane.showMessageDialog(null, e1);

        }
            return null;

        }
    });

Where should i edit my code? Can anyone pls help me with this?

Steffi Matchado
  • 134
  • 2
  • 10

1 Answers1

0

I got the output with the following output

vv.setVertexToolTipTransformer(new Transformer<String, String>() {
        public String transform(String v) {

                try {

                 String bb = "SELECT * FROM interr";
                Statement pest = connection.createStatement();
                ResultSet v1 = pest.executeQuery(bb);   
                while(v1.next())
                    if(v.toString().equals(v1.getString("Mole1")))
                 na[i] = v1.getString("Pubchem_ID");
                System.out.println(na[i]);
                v=na[i].toString();
                return "PUBMED:"+v.toString();
            }
        catch (Exception e1) {
            JOptionPane.showMessageDialog(null, e1);

        }
            return null;

        }
    });
Steffi Matchado
  • 134
  • 2
  • 10
  • I would suggest querying and storing this information when (or before) you paint the graph instead of creating a query everytime someone hovers the mouse over the vertex. Unless the data changes while the program is open. – Moh-Aw Dec 09 '15 at 09:26
  • Agreed, you should preload the data if that's feasible, and also build a Map from your vertex objects to the Tooltip text that you want to use, once; then you just do lookups into that. If you do need to worry about the tooltip text changing, then you should at least do a targeted lookup in your database (look up just the entry you want, not all of them and then iterate through them). – Joshua O'Madadhain Dec 11 '15 at 02:09