• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

refreshing display from a tree control

Hi,

Im having a tree control with three nodes, lets say A, B, C., and Im also having around 10 textfields on which, data is displayed as a particular node is selected. On selection of A, I am displaying some data on 5 textfields, and on selection of B, I am displaying other 5.
What I want to get here is, when i go back to A node, the data that is being displayed by B node to disappear, something like refresh,etc.

For eg:-

      A --------------------------> data is displayed on 5 textfields
      |
       --B------------------------> data is displayed on other 5 textfields
            |
             ----
                  C

so when I choose A node again, this data from B node should dissappear.

All contributions will be greatly appreciatted.

Thanks.
0
vihar123
Asked:
vihar123
  • 14
  • 8
  • 6
  • +1
1 Solution
 
objectsCommented:
As well as displaying fields when a node is selected, you could also clear all other fields as required (or just clear all fields before setting any).

Another option would be to have a seperate form for each node, and swicth the form displayed using a CardLayout.
0
 
girionisCommented:
Try to set the text on the textfields that are filled up from B node by using

setText("");
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
vihar123Author Commented:
jTree1.addTreeSelectionListener(new TreeSelectionListener() {
              
                public void valueChanged(TreeSelectionEvent evt) {
                                                                                
               TreePath tp = evt.getNewLeadSelectionPath();
                             Connection conn2;
                               Statement stmt2;
                               ResultSet rset2 = null;
                               DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) tp.getLastPathComponent();                               
                               String empNo = node1.toString();
             
                                                              
                               try
                                {
                              DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
                     
                        conn2 = DriverManager.getConnection ("jdbc:oracle:thin:@fe64700:1521:tanska","anska_test", "praktikant2004");
           
                              stmt2 = conn2.createStatement ();
                                  rset2 = stmt2.executeQuery("select * from regdet WHERE ang_nr1 = '" + empNo + "'");
                                  
                               
                               while (rset2.next())
                           {
                            jTextField1.setText(node1.toString());
                            jTextField2.setText(rset2.getString("ang_nr1"));
                            jTextField3.setText(rset2.getString("prod_bez1"));
                            jTextField4.setText(rset2.getString("kunde_nr1"));
                            jTextField5.setText(rset2.getString("ref_nr1"));
                            jTextField6.setText(rset2.getString("proj_nr1"));
                            jTextField7.setText(rset2.getString("basisprojekt1"));
                            /*jTextField8.setText(rset2.getString("ver_nr1"));
                                    jTextField9.setText(rset2.getString("gesc_jahr1"));
                                    jTextField10.setText(rset2.getString("ver_besh1"));
                                    jTextField11.setText(rset2.getString("curr1"));
                                    jTextField12.setText(rset2.getString("ges_kalk1"));
                                    jTextField13.setText(rset2.getString("kalk_ele1"));
                                    jTextField14.setText(rset2.getString("kalk_mek1"));*/
                           }
                              
                                          conn2.close();
                                          stmt2.close();
                                          rset2.close();
                                          
                                     
                                  }
                 
                 
                 
                          catch (SQLException e)
                                {
                                    System.out.println(e);
                                }
                                  
                           
                             Connection conn3;
                               Statement stmt3;
                               ResultSet rset3 = null;                                                 
                               String verNo = node1.toString();
                               
                               
                   try
                                {
                              DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
                     
                        conn3 = DriverManager.getConnection ("jdbc:oracle:thin:@fe64700:1521:tanska","anska_test", "praktikant2004");
           
                              stmt3 = conn3.createStatement ();
                                  rset3 = stmt3.executeQuery("select * from regdet WHERE ver_nr1 = '" + verNo + "'");
                                              
                               while (rset3.next())
                           {
                            jTextField8.setText(rset3.getString("ver_nr1"));
                                    jTextField9.setText(rset3.getString("gesc_jahr1"));
                                    jTextField10.setText(rset3.getString("ver_besh1"));
                                    jTextField11.setText(rset3.getString("curr1"));
                                    jTextField12.setText(rset3.getString("ges_kalk1"));
                                    jTextField13.setText(rset3.getString("kalk_ele1"));
                                    jTextField14.setText(rset3.getString("kalk_mek1"));
                               }
                              
                                          conn3.close();
                                          stmt3.close();
                                          rset3.close();                                           
                                    
                                  }
                 
                          catch (SQLException e)
                                {
                                    System.out.println(e);
                                }
                      
                                                                                                 
                                                                                        
                                                                                        }
               
                                                                                                    }
       
                                                          );      
0
 
vihar123Author Commented:
oops i pressed enter before writing, well to add to the above code, i did use setText for the B node, but I dont know how to clear these values when again A node is selected.
0
 
objectsCommented:
you really shouldn't be making db calls from the gui thread, that'll result in porr gui responsiveness.
0
 
objectsCommented:
Clear them with setText("");
0
 
zzynxSoftware engineerCommented:
This is what I do in such cases.
Let's call the panel where the text fields are displayed "rightPanel".
On every selection change in the tree the first thing I do is:

   rightPanel.removeAll();  // Remove all the previous stuff
   try {

          // Some logic to decide which JPanel to show according to the selected node
          if ( ) {
             PropertiesPanel1 propsPnl = new PropertiesPanel1(); // showing the information for your node. Probably pass the selected node as parameter
             rightPanel.add(propsPnl);
          } else if ( ) {
             PropertiesPanel2 propsPnl = new PropertiesPanel2(); // showing the information for your node. Probably pass the selected node as parameter
             rightPanel.add(propsPnl);
          }
          // and so on if needed

   } finally {
      rightPanel.revalidate();
      rightPanel.repaint();
   }

So in fact the panel within rightPanel is totally recreated for every new selection
0
 
objectsCommented:
easiest would be to add a method that cleared everything, and call that first when a node is selected.
0
 
objectsCommented:
No need to be creating, adding and removing panels, that just creates extra unnecessary work for the application.
0
 
zzynxSoftware engineerCommented:
So in your case PropertiesPanel1 contains the text fields 1 to 7 while PropertiesPanel2 contains the text fields 8 to 14.
Switching between tree nodes = removing the previously created PropertiesPanel1 and creating a new PropertiesPanel2 or vice versa.
No clearing problems.
0
 
objectsCommented:
public void valueChanged(TreeSelectionEvent evt) {
   clearForm();
   // now set the required fields
   ....
}

private void clearForm()
{
    jTextField1.setText("");
    jTextField2.setText("");
    jTextField3.setText("");
...
}

                                                                       
0
 
objectsCommented:
> No clearing problems.

Just a proliferation of unnecessary objects for the gc to clean up :)
0
 
zzynxSoftware engineerCommented:
>> No need to be creating, adding and removing panels, that just creates extra unnecessary work for the application.

vihar123,

   That's just his opinion. I use it and I'm quite comfortable with it.
   Moreover, why showing 7 text fields when they don't have to display anything useful for the selected tree node?
0
 
girionisCommented:
>  but I dont know how to clear these values when again A node is selected.

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21116390.html#11961272
0
 
objectsCommented:
> Moreover, why showing 7 text fields when they don't have to display anything useful for the selected tree node?


Then you could also use seperate forms as I mentioned earlier.
0
 
vihar123Author Commented:
>>>>Try to set the text on the textfields that are filled up from B node by using

setText("");


where exactly i shld write this, if i write this inside try block, itll give me exceptions, and outside i cant use these variables.
0
 
girionisCommented:
> where exactly i shld write this, if i write this inside try block, itll give me exceptions, and outside i cant use these variables.

In the block of code that it is called when the node A is selected. Then the setText(""); should be called on the text fields of the node B.
0
 
girionisCommented:
If this is node A, then do:

while (rset2.next())
                         {
                          jTextField1.setText(node1.toString());
                          jTextField2.setText(rset2.getString("ang_nr1"));
                          jTextField3.setText(rset2.getString("prod_bez1"));
                          jTextField4.setText(rset2.getString("kunde_nr1"));
                          jTextField5.setText(rset2.getString("ref_nr1"));
                          jTextField6.setText(rset2.getString("proj_nr1"));
                          jTextField7.setText(rset2.getString("basisprojekt1"));

                          // Node B text fields.
                          jTextField8.setText(rset2.getString(""));
                              jTextField9.setText(rset2.getString(""));
                              jTextField10.setText(rset2.getString(""));
                              jTextField11.setText(rset2.getString(""));
                              jTextField12.setText(rset2.getString(""));
                              jTextField13.setText(rset2.getString(""));
                              jTextField14.setText(rset2.getString(""));
                         }
0
 
objectsCommented:
> where exactly i shld write this,

I'd put it in a seperate method that cleared all the fields as I outline above.
You can then call it whenever you need to clear the form.
0
 
girionisCommented:
Sorry, it should be:

 // Node B text fields.
                          jTextField8.setText("");
                              jTextField9.setText("");
                              jTextField10.setText("");
                              jTextField11.setText("");
                              jTextField12.setText("");
                              jTextField13.setText("");
                              jTextField14.setText("");
0
 
objectsCommented:
public void valueChanged(TreeSelectionEvent evt) {
   clearForm();
   // now set the required fields as you already do
   ....
}

private void clearForm()
{
    jTextField1.setText("");
    jTextField2.setText("");
    jTextField3.setText("");
...
}
0
 
vihar123Author Commented:
Hey,

thanks objects, its working

and ofcourse thanks to all for ur informative contributions.
0
 
zzynxSoftware engineerCommented:
>> and ofcourse thanks to all for ur informative contributions.
You're welcome
0
 
objectsCommented:
> thanks objects, its working

good stuff, let us know if you need further assistance :)
0
 
girionisCommented:
> and ofcourse thanks to all for ur informative contributions.

np :)
0
 
vihar123Author Commented:
>> np :)

sorry again, i get excited when its working and usually forget the option of split points, well i think its a big process again to put it into community and reallocate points.
so this time please excuse me and i promise ill not repeat this again.

thanks for your understanding.  :-))))
0
 
zzynxSoftware engineerCommented:
> i think its a big process again to put it into community and reallocate points.
Not at all.

Just FYI:
1) You simply post a zero-point question in http://www.experts-exchange.com/Community_Support/

Subject: Moderator Please Reopen
Body:
           Please reopen this question:
           http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21116390.html

2) A moderator reopens it (within hours or at most two days) and you get a mail
3) You simply re-accept with points split

>> so this time please excuse me and i promise ill not repeat this again.
That's OK ;°)
0
 
girionisCommented:
>so this time please excuse me and i promise ill not repeat this again.
>
>thanks for your understanding.  :-))))

Don't worry, as long as you are happy with the solution :)
0
 
vihar123Author Commented:
>>>Don't worry, as long as you are happy with the solution :)

thanks a lot.
------
a small question again, im getting sql exception (SQLException: ORA-01722: invalid number) when im clicking the C node.
what does it mean?


0
 
girionisCommented:
ORA-01722 invalid number

Cause: The attempted conversion of a character string to a number failed because the character string was not a valid numeric literal. Only numeric fields or character fields containing numeric data may be used in arithmetic functions or expressions. Only numeric fields may be added to or subtracted from dates.

Action: Check the character strings in the function or expression. Check that they contain only numbers, a sign, a decimal point, and the character "E" or "e" and retry the operation.

0
 
zzynxSoftware engineerCommented:
0
 
objectsCommented:
snap
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 14
  • 8
  • 6
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now