in Search
     
Latest post 03-25-2008 11:40 PM by imageek. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 03-25-2008 11:40 PM

    • imageek
    • Top 200 Contributor
    • Joined on 10-21-2007
    • Posts 4
    • Points 65

    My Simple Refresh Problem

    I'm using Netbeans 6.0.1. I've created a generic Java Desktop Application - Database Application from our library. Then added a little searchbar on the top. It looks like this:



    My objectives is:

    * The user will type something on the JTextField.
    * Then the user will click the "SEARCH" button.
    * Upon clicking, the query will be updated from: SELECT b FROM Books b
    * Into: SELECT b FROM Books b WHERE b.title LIKE \"%" + jTextField1.getText () + "%\"
    * Then call the "refresh" method (just like how the refresh booton work) to refresh the table


    I tried:


        private void jButton1MouseReleased(java.awt.event.MouseEvent evt)
        {
            query = entityManager.createQuery ( "SELECT b FROM Books b WHERE b.title LIKE \"%" + jTextField1.getText () + "%\"" );
        refresh(); // This ain't working
        }


    But nothing happens, I made some breakpoints and follow-through what is happening. And this is the code that is concerned with the "refresh" button:


        @Action
        public Task refresh ()
        {
            return new RefreshTask ( getApplication () );
        }

        private class RefreshTask extends Task
        {

            RefreshTask ( org.jdesktop.application.Application app )
            {
                super ( app );
            }

            @Override protected Void doInBackground ()
            {
                try
                {
                    setProgress ( 0 , 0 , 4 );
                    setMessage ( "Rolling back the current changes..." );
                    setProgress ( 1 , 0 , 4 );
                    entityManager.getTransaction ().rollback ();
                    Thread.sleep ( 1000L ); // remove for real app
                    setProgress ( 2 , 0 , 4 );

                    setMessage ( "Starting a new transaction..." );
                    entityManager.getTransaction ().begin ();
                    Thread.sleep ( 500L ); // remove for real app
                    setProgress ( 3 , 0 , 4 );

                    setMessage ( "Fetching new data..." );
                    java.util.Collection data = query.getResultList ();
                    Thread.sleep ( 1300L ); // remove for real app
                    setProgress ( 4 , 0 , 4 );

                    Thread.sleep ( 150L ); // remove for real app
                    list.clear ();
                    list.addAll ( data );
                }
                catch ( InterruptedException ignore )
                {
                }
                return null;
            }

            @Override protected void finished ()
            {
                setMessage ( "Done." );
                setSaveNeeded ( false );
            }

        }


    But simply calling "refresh();" would simply ends in the "super(app);" statment. I made some quick lookup how the "refresh" button was setup, and all I could see is this:


            refreshButton.setAction(actionMap.get("refresh")); // NOI18N
            refreshButton.setName("refreshButton"); // NOI18N


    And I have no idea, how to call it. I'm really new to Java, I wish you could help me.
    • Post Points: 5
Page 1 of 1 (1 items)