We help IT Professionals succeed at work.
Get Started

Reload jTextPane on each double click...

k41d3n asked
Last Modified: 2008-02-01
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){
            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
            ResultDAO dao = new ResultDAO();
            SessionFactory sessionFactory = new Configuration().configure()
            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) {
        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);
        return jDialog;


    private JScrollPane getJScrollPane13() {
        if (jScrollPane13 == null) {
            jScrollPane13 = new JScrollPane();
        return jScrollPane13;


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


    private JTextPane getJTextPane() {
            jTextPane = new JTextPane();
        return jTextPane;

I think those are all the methods involved.

Thanks for your time.
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE