Link to home
Start Free TrialLog in
Avatar of k41d3n
k41d3n

asked on

Reload jTextPane on each double click...

I have my table listening for double clicks on a row, when it is double clicked, it pops up a jDialog with a Text Pane on it that shows data collected.

The issue is two fold.

First, when I double click and the dialog opens, I can see the data I want. However, if I double click on another row, I want it to show the data associated with that row in the same dialog, essentially switching the data I was looking at with the current data.

Right now it keeps showing the data for the first row I double click on. Even ifI close the dialog, I double click another row, it still shows the same data.

Secondly, In the method getResultsForSummary(), after it gets the Summary record and then the Set of result objects, it should iterate through, and for each record it should modify the string accordingly.

if I have a record with two result objects, the iteration only adjusts the string for one record, not two.


Some code:

The doClick action, called when I double click a row:

    protected void doDoubleClickAction(int rowIndex){
            getJDialog();
            jDialog.setVisible(true);
            System.out.println("The row with index " + rowIndex + " is double-clicked");
    }  

the  getResultsForSummary():

    private String getResultsForSummary() {
        String results = null;
        TableModel model = jTable.getModel();
        int row = jTable.getSelectedRow();
        Integer sid = (Integer)model.getValueAt(row, 6);
        try {
            //load the configuration file
            _RootDAO.initialize();
           
            ResultDAO dao = new ResultDAO();
            SessionFactory sessionFactory = new Configuration().configure()
            .buildSessionFactory();
            Session session2 = sessionFactory.openSession();
            //find all records
            Summary summary = (Summary)session2.load(Summary.class, sid);
            Set records = summary.getResult();
            //Get all rows.
            int recs = records.size();
            System.out.println("Size of results " + recs);
            Iterator it = records.iterator();
            while (it.hasNext()) {
                Result element = (Result) it.next();
                String testName = element.getScript();
                String user = element.getSummary().getTester();
                System.out.println("User: " + user);
                String testTime = element.getTimestamp().toString();
                results = testName + "\n" + user + "\n" + testTime + "\n\n";
            }
        } catch (HibernateException e) {
            atelog.error(e);
            e.printStackTrace();
        }
        return results;
    }

The jDialog....

   /**
     * This method initializes jDialog      
     *       
     * @return javax.swing.JDialog      
     */    
    private JDialog getJDialog() {
        if (jDialog == null) {
            jDialog = new JDialog(this);
            jDialog.setTitle("Test Results");
            jDialog.setSize(500, 400);
            jDialog.setLocation(jContentPane.getWidth() / 2, jContentPane
                    .getHeight() / 2);
            jDialog.add(getJScrollPane13());
        }
        return jDialog;
    }

getJScrollPane13:


    private JScrollPane getJScrollPane13() {
        if (jScrollPane13 == null) {
            jScrollPane13 = new JScrollPane();
            jScrollPane13.setViewportView(getJPanel2());
        }
        return jScrollPane13;
    }

getJPanel2

    private JPanel getJPanel2() {
        if (jPanel2 == null) {
            jPanel2 = new JPanel(new BorderLayout());
            jPanel2.add(getJTextPane(), BorderLayout.CENTER );
        }
        return jPanel2;
    }

getJTextPane:

    private JTextPane getJTextPane() {
            jTextPane = new JTextPane();
            jTextPane.setEditable(false);
            jTextPane.setText(getResultsForSummary());
            jTextPane.setVisible(true);
        return jTextPane;
    }

I think those are all the methods involved.

Thanks for your time.
ASKER CERTIFIED SOLUTION
Avatar of StillUnAware
StillUnAware
Flag of Lithuania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of k41d3n
k41d3n

ASKER

That worked, absolutely.