Menu

Chart display fails to update

Help
John Smith
2010-05-25
2023-03-20
  • John Smith

    John Smith - 2010-05-25

    I have used JChart2D v3.1.0 with some success for a simple line chart.

    When I call a method directly from main which call trace insertion methods, it works fine, updating the display as the traces are inserted.

    But when I call the same methods from an ActionEvent method (triggered by a menu item), the chart does not update its display, until the original method returns.

    I have tried calling repaint and setRequestedRepaint, but I cannot get the chart to update as the trace is submitted.

    Mr. Westerman has suggested that unreleased updates putting chart display methods in a separate thread might have fixed this.

    Can anyone verify that? When will there be a new released version?

    Thanks.

     
  • John Smith

    John Smith - 2010-05-28

    The jChart2D is not the problem here.

    None of my menu bar controls update their display either, when display methods are called from a menu event, but everything updates when called from main.

    And they all update (but runs slow) when the menu event triggers separately threaded methods which update the display items.

    It appears that display update code is in-lined when calling methods from main, but locked out when calling from a menu event.

    Seems to be a "feature" of Java (Swing?) Maybe there's a way to relinquish processor time to allow the display to update?

     
  • Achim Westermann

    Hi rob,

    perhaps you could post a code snippet how you update your controls. Perhaps you directly invoke paint or paintComponent? That for example must not be done and if invoked from a menu event could explain why your updates are blocked until the event dispatching thread has finished it's work.

     
  • John Smith

    John Smith - 2010-06-01

    I do not invoke paint or paintComponent (though I tried that; it did not work)

    Here is my main:

    static public void main(String args)
    {
    try
    {
    //Create a new instance of our application's frame, and make it visible.
    JXFrame jtf = new JXFrame();
    Dimension szScreen = Toolkit.getDefaultToolkit().getScreenSize();
    int nCenterX = szScreen.width >> 1;
    int nCenterY = szScreen.height >> 1;
    jtf.setBounds(nCenterX - 400, nCenterY - 200, 800, 400);
    jtf.setVisible(true);

    if(!jtf.openFile(args))
       System.exit(1);

    }
    catch (Throwable t)
    {
    t.printStackTrace();
    //Ensure the application exits with an error condition.
    System.exit(1);
    }
    }

    which calls openFile()

    boolean openFile(String sFile)
    {
    m_bProcess = true;
    SomeClass s = new SomeClass(this, sFile);
    while(m_bProcess)
    {
    s.drawMenuBarText();
    }
    return true;
    }

    class SomeClass
    {
          JFrame m_jframe;
         SomeClass(JFrame jtf, File sFile)
         {
              m_jframe = jtf;
         }

        void drawMenuBarText()
        {
             m_jframe.displayText(1000);
        }
    }

    class JXFrame extends JFrame
    {
    void displayText(int nVal)
    {
    m_sDisplay = String.valueOf(nVal);
    JTextTrades.setText(m_sDisplay);
    }
    }

    When called this way, the menubar (and jChart2D) update as the display function is called.

    When the same drawMenuBarText method is called from a menu item such as:

    void openItem_actionPerformed(java.awt.event.ActionEvent event)
    {
    // to do: code goes here.
    openItem_actionPerformed_Interaction1(event);
    }

    void openItem_actionPerformed_Interaction1(java.awt.event.ActionEvent event)
    {
    openFileDialog.setFile("*.csv");
    try
    {
    // openFileDialog Show the FileDialog
    openFileDialog.setVisible(true);
    } catch (Exception e)
    {
    }

    String sFile = openFileDialog.getFile();
    if(sFile == null)
    return;

    if(sFile.indexOf('*') == -1 && sFile.indexOf('?') == -1)
    {
    openFile(sFile);
    }
    }

    The menubar text and jChart2D do not update until openFile returns.

     
  • Anonymous

    Anonymous - 2023-03-20

    main is not the Event Dispatch thread. You are making Swing calls from another thread. You need to create your Swing app then use:
    SwingUtilities.invokeLater(new MyApp());

    where
    private static class MyApp
    implements Runnable
    {
    public void run()
    {
    // Your Swing calls here.
    }
    }

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.