Results 1 to 6 of 6

Thread: Updating A JPanel

  1. #1
    Join Date
    Jul 2003
    Posts
    234
    Rep Power
    0

    Default Updating A JPanel

    Imworking on a program in java for school everything else works fine except for the refresh function with only clears the text fields but not the panel with the picture the data displayed is pulled from a database below is the code that populates the fields after the search button is pressed

    Code:
     
    
    public void showRecord(ResultSet res)   {
    	try  {
    		
    		int count = 0;
    		while(res.next()){
    			count++;
    			id.setText(res.getString(1));
    			lname.setText(res.getString(2));
    			fname.setText(res.getString(3));
    			lnum.setText(res.getString(4));
    			vmake.setText(res.getString(5));
    			vmod.setText(res.getString(6));	
    			pictureName = res.getString(7);
    			picture = new ImageIcon("images\\"+ pictureName);
    			JLabel pic = new JLabel(picture);
    			
    			PiturePanel.add(pic );
    			pic.setText("");
    			Parkin.setText(res.getString(8));	
    			
    			
    		}
    		if(count == 0)
    		{
    			JOptionPane.showMessageDialog(this,"Record not found");
    		}
    		
    	}


    And heres the code that clears the fields

    Code:
    if (e.getSource()==clear)
    		{
    			
    			id.setText("");
    			lname.setText("");
    			fname.setText("");
    			lnum.setText("");
    			vmake.setText("");
    			vmod.setText("");
    			Parkin.setText("");
    			PiturePanel.repaint();
    		}
    	}

    heres the GUI for reference



    can anybody tell me or point mi to finding how to refressh that picture panel
    "I pledge allegiance to a country without borders and without politicians" - Maximus
    al·le·giance: Loyalty or the obligation of loyalty, as to a nation, sovereign, or cause.

  2. #2
    Join Date
    Feb 2005
    Posts
    85
    Rep Power
    0

    Default

    I am no java programmer but I have a suggestion, here goes:

    Store a blank picture (e.g. a picture that is just a white background), when the user hits refresh then display that blank picture
    Code King aka Code WizZzard: Motivated By The Challenge, Driven By The Will To Succeed.

    In The Land Of Programmers, The Code WizZzard Is KING. Sen on anything VB

  3. #3
    Join Date
    May 2006
    Posts
    196
    Rep Power
    0

    Default

    Quote Originally Posted by ToxXxic View Post
    I am no java programmer but I have a suggestion, here goes:

    Store a blank picture (e.g. a picture that is just a white background), when the user hits refresh then display that blank picture
    I was thinking along the same lines. That should at least provide a functional fix.

    Hey Max, I also noticed that your clear code is not removing the picture from the panel, so that's why it still displays the pic when you use the repaint method.
    Last edited by Ghionw; Nov 26, 2007 at 09:41 AM.
    I went to a bookstore and asked the saleswoman, "Where's the self-help section?" She said if she told me, it would defeat the purpose.
    Windows 7 Pro, Gigabyte MA785GM-US2H, AMD Athlon II 245, OCZ Reaper 2X2GB DDR2 1066, WD 500GB+WD 200GB, Cosair 400W, 23" eMachine 1080p Monitor

  4. #4
    Join Date
    Oct 2005
    Posts
    745
    Rep Power
    0

    Default

    Quote Originally Posted by Maximus View Post
    I
    [code]


    And heres the code that clears the fields

    Code:
    if (e.getSource()==clear)
    		{
    			
    			id.setText("");
    			lname.setText("");
    			fname.setText("");
    			lnum.setText("");
    			vmake.setText("");
    			vmod.setText("");
    			Parkin.setText("");
    			PiturePanel.Just Clear all the controls or if there 
    are any other inner controls then specifically remove the label that stores the pic.
    
    		}
    	}
    I can't remember the function but try PiturePanel.Remove(); or something along those lines.
    3.14159265358979323846264338327950288
    4197169399375105820974944592307816406
    28620899862803482534211706798 pi 101

  5. #5
    Join Date
    May 2004
    Posts
    168
    Rep Power
    0

    Default

    Try using the following, this should solve your problem.

    Code:
    if (e.getSource()==clear)
    		{
    			
    			id.setText("");
    			lname.setText("");
    			fname.setText("");
    			lnum.setText("");
    			vmake.setText("");
    			vmod.setText("");
    			Parkin.setText("");
    			PiturePanel.removeAll();
                            PiturePanel.validate();
    		}
    	}
    ||| Knowledge is Power |||

  6. #6
    Join Date
    Jul 2003
    Posts
    234
    Rep Power
    0

    Default

    Quote Originally Posted by ToxXxic View Post
    I am no java programmer but I have a suggestion, here goes:

    Store a blank picture (e.g. a picture that is just a white background), when the user hits refresh then display that blank picture
    ive tried this when the picture comes in the orignal photo gets pushed to the left so now i have 2 pic on one panel

    i havent tried the validate(); ive tried the removeAll(); dosent work thanks guy ill give it a shot again
    "I pledge allegiance to a country without borders and without politicians" - Maximus
    al·le·giance: Loyalty or the obligation of loyalty, as to a nation, sovereign, or cause.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •