SwingWoker

Hi All
I am facing a flickering problem in applet when using SwingWorker class from sun i want to do some background processing in event thread SwingUtilities.invokeLater did help me but not that much GUI used
to get freeze to prevent that i have used SwingWorker seems to be everything is working fine but some flickering is happening in applet
can somebidy tell me why is it happening and what is the solution for the same pls note This problem arise when applet is loaded with huge data
can somebidy tell me about Applet Double buffering how do i do that will my problem gets solved by doing double buffering
pls help required urgently
Rishi

1. method get() inside done() returns only Exceptions if exist
2. better (not required) would be have same arrays type for TableHeader and value for rows too
3. add value for row(s) inside loop from ResultSet, and vector must be reinitialized vct ´new Vector<Object>
4. you added value from ResultSet to the plain Vector, this way never will be added to the TableModel
5. lots of another mistakes about implementations for SwingWorker,
then possible ways
1) (loosing stepped adding for records) search for ResulsetTableModel better would be TableFromDatabase, then you'd be invoke that from SwingWorker or Runnable#Thread
2) (loosing stepped adding for records) basically your SwingWorker could stay remained (notice just for testing purposes that as demonstrations you are able loading data for JTable from SwingWorker) change AbstractTableModel for DefaultTableModel
- load data without Thread#sleep(int) into doInBackground() to the Vector<Vector<Object>>
- on done() put Vector<Vector<Object>> to the DefaultTableModel
3) change your SwingWokrer and inside method publish() put row to the DefaultTableModel

Similar Messages

  • Different type of threads?

    Dear,
    Is it we should use different methods to invoke the threads for different purposes? eg. use swingworker class to start time comsuming task...; use invokelater() to start a thread which used to alert the GUI... is it true?

    hi,
    Swing components are not Thread-safe, what this means is that the components can be accessed only from a single thread at a time (Generally the event-dispatching thread) after they have been realized, there are certain methods though that are gauranteed to be thread-safe (like paint, thread-safe methods are marked out in the API ref).
    herez the golden rule:
    Once a Swing component has been realized, all code that might affect or depend on the state of that component should be executed in the event-dispatching thread.
    A component becomes realized if itz paint method is going to be called or has been called.
    Event-Dispatching thread is the thread which handles the event-handling code..
    Now if the task at hand is going to take up a lot of time u should not do it in the event-dispatching thread, you should in turn do it in a separate thread.. but letz say the results of the operation require u to update a gui, u cannot update the gui from that thread (non event-dispatching thread) , for updating the gui you would use the SwingUtilities.invokeLater or SwingUtilities.invokeAndWait methods. SwingWorker is a separate Class (not part of jdk) that can be downloaded from the sun site at
    http://java.sun.com/products/jfc/tsc/articles/threads/src/SwingWorker.java
    the idea of this class is that it eases the task of the programmer who has to create new threads that will take up time to execute, this class provides a mechanism to start a thread to perform a task that will take time, also after the task is over it automatically calls a method (finished()) in which you can then do whatever is required with the result (for eg update the gui using the result in a event-dispatching thread using the SwingUtilities.invokeAndWait())..
    for eg If you are doing IO operations that are going to take time you could use the SwingWorker like
    SwingWorker worker = new SwingWorker()
       public Object construct()  //method defined in swingwoker which is to be overridden
              return myMethod(); //myMethod returns a object after taking lotz of time letz say..     
       public void finished()   //method is automatically invoked by swingwoker after myMethod finishes.
            Object obj = get();  // get() returns the value returned by myMethod();
    worker.start();now letz say you are doing some task in a non-event dispatching thread and you want to update the gui (you should not directly do it from that thread as it can lead to problems) you would do it using the SwingUtilities.invokeLater or SwingUtilities.invokeAndWait
    eg
      Runnable myRunnable = new  Runnable()
            public void run()
                 //update the gui here
        SwingUtilities.invokeAndWait(myRunnable);the invokeAndWait method blocks whereas the invokeLater does not (so itz preferable to use this !!)..
    hope that helpzz
    cheerz
    ynkrish

  • Problems updating gui in JApplet

    Hi,
    I have a JApplet with a JPanel with another JPanel ? TreePanel ? containing a JScrollPane with a JTree.
    When init() is run in MyApplet, treePanel is initiated with a JTree, with test data hardcoded in TreePanel?s constructor. I want the tree to change every time a thread loops, by calling method treePanel.updateResultTree(root) from the thread, with a new root. To test this, I have hardcoded a new tree content in the thread to pass to the TreePanel. In method updateResultTree(root), I remove the existing JTree from JScrollPane and add a new JTree to it, with the new root. Then I repaint the JScrollPane.
    When I run the applet, the initial tree is displayed, but it is not updated with the new JTree for the first thread loop as expected. How is the gui in a JApplet refreshed/updated?? Will SwingWoker update the gui automatically without forcing repaint()?
    Please help, I'm so stuck! Thanks in advance!
    MyApplet
    public class MyApplet extends JApplet {
       private TreePanel _treePanel;
       private UpdateHandler _updateHandler;
       private Thread _updateThread;
       public void init() {
          super.init();
          _treePanel = new TreePanel();
          // Updating thread
          _updateHandler = new UpdateHandler();
          _updateThread = new Thread(_updateHandler);
          _updateThread.start();
          // Initialize gui
          JPanel bigPanel = new JPanel();
          bigPanel.setLayout(new BoxLayout(bigPanel, BoxLayout.X_AXIS));          
          getContentPane().add(bigPanel, BorderLayout.CENTER);   
          _treePanel = new JPanel();
          bigPanels.add(_treePanel);
       // Updates the GUI every X seconds
       private class UpdateHandler implements Runnable {
          public final static int UPDATE_INTERVAL = 10;
          public UpdateHandler() { }
          public void run() {
             try {
                _displayResults();
             } catch (InterruptedException ie) {
       private synchronized void _ displayResults () throws InterruptedException {
          while(true) {
             // Resolve a new DefaultMutableTreeNode object as root to be updated in GUI
             // (For test)
             DefaultMutableTreeNode root = new DefaultMutableTreeNode(new Result("Root"));
             DefaultMutableTreeNode child_1 = new DefaultMutableTreeNode(new Result("Result X"));
             DefaultMutableTreeNode child_2 = new DefaultMutableTreeNode(new Result("Result Y"));
             DefaultMutableTreeNode child_11 = new DefaultMutableTreeNode(new Result("Result X1"));
             root.add(child_1);
             root.add(child_2);
             child_1.add(child_11);
             // Update the GUI 
             _treePanel.updateTree(root);
             wait(UPDATE_INTERVAL*1000);
    }TreePanel
    public class TreePanel extends JPanel {
       private JScrollPanel _treeSrcoll;
       private JTree _tree;
       TreePanel() {
          super();
          // Test tree, displayed in applet?s init()
          DefaultMutableTreeNode root = new DefaultMutableTreeNode (new Result("Root"));
          DefaultMutableTreeNode child_1 = new DefaultMutableTreeNode (new Result("Result 1"));
          DefaultMutableTreeNode child_2 = new DefaultMutableTreeNode (new Result("Result 2"));
          DefaultMutableTreeNode child_11 = new DefaultMutableTreeNode (new Result("Result 4"));
          DefaultMutableTreeNode child_12 = new DefaultMutableTreeNode (new Result("Result 5"));   
          root.add(child_1);
          root.add(child_2);
          child_1.add(child_11);
          child_1.add(child_12);
          _tree = new JTree(root);
          _treeScroll = new JScrollPane(_tree);
          add(_treeScroll, BorderLayout.CENTER);
       public void updateTree(DefaultMutableTreeNode  theRoot) {
          if (theRoot != null) {
             if (_tree!= null) {
                _treeScroll.remove(_tree);
             _ tree = new QCTree(root);     
             _treeScroll.add(_tree);
          } else {
             JLabel label = new JLabel("No result tree structure is available");
            _treeScroll.add(label);
         _treeScroll.repaint();
    }Result
    public class Result {
       private String _name; 
       public Result(String name) {
          _name = name;
       public String toString() {
          return _name;

    I found the error:
    I need to use
    treeScroll.getViewPort().add(tree);
    and
    treeScroll.getViewPort().remove(tree);

Maybe you are looking for

  • Custom search help for characteristic based variant

    Dear Experts, I have characteristic based variant report, my requirement is, in any  Article(matnr) related transaction( Ex: MM43, VA01..) I required custom search help based on these characteristics and i will populate article/variant. Attached repo

  • Can't shut down after opening Java Control Panel

    Hello, I'm just a regular guy with Windows ME and since I installed JRE 1.4.2_02 (for Mozilla 1.5), I can't shut down my pc after opening the Java Control Panel. Javaw.exe stays in memory (Norton System Information) even after the JCP has been closed

  • Document number ranges changes

    Dear friends, While creating the document number ranges for current year, user wrongly changed the previous year number ranges, now it is giving new number ranges for new documents which are posted in previous year, how to reset the previous number r

  • Debug aplication started using ant

    Hello, I wonder if it is possible to stop and debug an aplication in a breakpoint when this aplication was started using ant from eclipse as IDE. I use eclipse ver. 3.0. thanks a lot for any help or ideea

  • "an error occurred when attempting to change modules" I can not uninstall its grayed out.

    I installed lightroom but at opening i have an error "an error occurred when attempting to change modules" I can not uninstall its grayed out.