1 Reply Latest reply: Oct 26, 2010 9:27 AM by 806484 RSS

    Retrieve the values of Swing Objects if they are local variables

    806484
      Hi, i am new to this forum.
      Have spent many hours on-line and looking at the API for JDI and cannot seem to find an answer to my question.
      I have been looking at JDI and have so far been able to access all the local variables and get their values. However, the value of a Swing component is a Swing Component.
      For example, if i call

      StackFrame.getValue(“a Swing component”)

      i get “javax.swing.JPanel(id=655)”

      Is there any method for accessing the values for the JPanel ie height, width etc.

      For my 4th year project at uni, i have decided to try and build an exploded view of Gui's built in swing. Obviously the first step here is to be able to analyse the target code. Reflection is useless to me as you are unable to access local variables, which is necessary.

      Thanks in advance
        • 1. Re: Retrieve the values of Swing Objects if they are local variables
          806484
          figured out how too do it, the value is an object refernece which i can cast as such and then access the values of its internal fields ie

                         for (StackFrame s : stacks){
                              locals = s.visibleVariables();
                              
                              for (LocalVariable l : locals){
                                   if(l.typeName().startsWith("javax.swing")||
                                             l.typeName().startsWith("java.awt")){
                                        
                                        Value v =s.getValue(l);
                                        
                                        if (v instanceof ObjectReference && l.typeName().startsWith("javax.swing.")&& !l.typeName().startsWith("java.awt.event")){

                                             ObjectReference o = (ObjectReference)v;
                                             System.out.println("_-------------||NAME: " + l.name() + " TYPE :" + l.typeName());
                                             worker.populateSwingFrameFields(o);

          Edited by: 803481 on 26-Oct-2010 07:27