2016-05-03 7 views
1

ich die folgende MethodeJFreeChart Zoomposition wiederherstellen, nachdem Refresh

 private void passStingR(StringBuilder retVal) throws BadLocationException, Exception { 
     int getinitialscrollpos; 
     getinitialscrollpos = getinitialscrollPosition(scrollMEL); 


    //1. get chartPanel Bounds 
     Rectangle2D xy = chartPanel.getScreenDataArea(); 

      Rectangle bounds = chartPanel.getBounds(); 
      int horz = (int) bounds.getX();//need to get the correct x and y 
      int vertz = (int) bounds.getY(); 
      int width1 = (int) bounds.getWidth(); 
      int height1 = (int) bounds.getHeight(); 
      System.out.println(horz + " " + vertz + " " + width1 + " " +height1);//get positioning data 
    /////////////////////////////////  


     Document docR = null; 

     docR = loadXMLFromString(retVal.toString());//pull in the XML data into a new doc 
     populate1R(docR); 
     tableMEL.getTableHeader().setReorderingAllowed(false);//prevent user from changing column order now at refresh level 
     SimpleDateFormat time_formatterR = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
     String current_time_strR = time_formatterR.format(System.currentTimeMillis()); 
     updatetFieldDG.setText(current_time_strR); 
     middlePanel.add(scrollMEL); 
     scrollMEL.getVerticalScrollBar().setValue(getinitialscrollpos); 
     System.out.println("End" + getinitialscrollpos); 
     getTableData(tableMEL); 
     head(tableMEL); 
     createGraphGUI(); 

    //2.the problem lies here as i would expect the chartPanel.setBounds to restore the position that i got at 1. 

     chartPanel.setBounds(horz,vertz,width1,height1);//xywidthheight 
      System.out.println(chartPanel.getBounds());//set the positioning items as per the start 
//////////// 


     } 

Das Problem ist, haben, dass, wenn meine Daten aktualisiert wird ich die Zoom-Einstellung verlieren.

Ich habe daher versucht, die chartPanel Grenzen am Anfang der Methode zu erhalten und dann versuchen, es am Ende der Methode anwenden - aber die Zoom-Positionierung immer wieder auf die Standardposition zurück, die nur das Ganze ist Graph. Kann mir bitte jemand helfen?

+0

Es ist nicht klar, wo die Dinge schief gehen; Bitte bearbeiten Sie Ihre Frage so, dass sie eine [mcve] enthält, die Ihre aktuelle Vorgehensweise anzeigt. – trashgod

+0

@ trashgod Ich habe meine Frage aktualisiert – Ingram

+0

@ trashgod Ich war in den Leitfäden auf http://www.ing.iac.es/~docs/external/java/jfreechart/org/jfree/chart/ChartPanel.html durchsuchen kann aber nicht bekommen getScaledDataArea() funktioniert! – Ingram

Antwort

0

Ich arbeitete this out:

private void passStingR(StringBuilder retVal) throws BadLocationException, Exception { 
    int getinitialscrollpos; 
    getinitialscrollpos = getinitialscrollPosition(scrollMEL); 
    try { 
     CategoryPlot plot = (CategoryPlot) chartPanel.getChart().getPlot();//get plot of graph 
     //System.out.print("Plot Type" + plot); 
     ValueAxis rangeAxis = plot.getRangeAxis();//get range of axis of graph 
     System.out.print("Range " + rangeAxis);//get range lower and upper as an array 
     map.put(1, rangeAxis); 
    } catch (Exception e) { 
     System.out.print("Error has occured"); 
    } finally { 
    ////refresh data//// 
     Document docR = null; 
     docR = loadXMLFromString(retVal.toString());//pull in the XML data into a new doc 
     populate1R(docR); 
     tableMEL.getTableHeader().setReorderingAllowed(false);//prevent user from changing column order now at refresh level 
     SimpleDateFormat time_formatterR = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
     String current_time_strR = time_formatterR.format(System.currentTimeMillis()); 
     updatetFieldDG.setText(current_time_strR); 
     middlePanel.add(scrollMEL); 
     scrollMEL.getVerticalScrollBar().setValue(getinitialscrollpos); 
     System.out.println("End" + getinitialscrollpos); 
     getTableData(tableMEL); 
     head(tableMEL); 
     createGraphGUI(); 
     if (map.get(1) != null) { 
      System.out.print("get map" + map.get(1)); 
      CategoryPlot plot = (CategoryPlot) chartPanel.getChart().getPlot(); 
      plot.setRangeAxis(map.get(1));//get range of axis of graph 
     } 
    } 
}