Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: revalidating JPanel when image is deleted from file

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default revalidating JPanel when image is deleted from file

    When the user presses the delete button, the code below runs but, I cannot figure out why, the images I have deleted from the file directory won't update on pPanel. this panel consist of a JSplitPane which consists of a JScrollPane and bPanel (for the buttons) and the JScrollPane has a JList which has a DefaultModelList.


     class dListener implements ActionListener {
    			public void actionPerformed(ActionEvent event) {
    				//System.out.println("delete");
     
    				if(listofFiles.length < 0)
    				{
    					return;
    				}
     
    				if(event.getSource() == dButton)
    				{
    					File folder = new File(path);
    					File[] listofFiles = folder.listFiles();
     
    					int a = list.getSelectedIndex();
     
    					try {
    						listofFiles[a].delete();
    						System.out.println(listofFiles[a].getName() + " is deleted");
     
    						//bPanel = buttonPanel(bPanel);
    						//listModel = loadImages();
    						//list = new JList(listModel);
    						//photoLister = new JScrollPane(list);
    						//imageSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, photoLister, bPanel);
     
    						pPanel.revalidate();
    						pPanel.repaint();
     
    					} catch (Exception x) {
     
    						x.printStackTrace();
    					}
    				}
     
    			}
    	 }


  2. #2
    Junior Member
    Join Date
    Apr 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Have you tried reprinting the whole frame?

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: revalidating JPanel when image is deleted from file

    why, the images I have deleted from the file directory won't update on pPanel.
    Can you explain what "update on pPanel" means?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Mar 2013
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: revalidating JPanel when image is deleted from file

    Quote Originally Posted by Norm View Post
    Can you explain what "update on pPanel" means?
    what I mean by "update on pPanel" is that once I have removed an image path from my file system, I want it to show on the panel that it has been deleted/removed

    --- Update ---

    Quote Originally Posted by rockking8350 View Post
    Have you tried reprinting the whole frame?
    I have, in my main class I did f.revalidate(); and f.repaint();

    its still not updating.

    I tried creating a new DefaultModelList, JList, JScrollPane, and JSplitPane. but when I do that, the pictures update & the bPanel disappears (panel with buttons) [bPanel is created with a seperate function]

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: revalidating JPanel when image is deleted from file

    I want it to show on the panel that it has been deleted/removed
    Where do you want it shown? Is there a component that is used to show messages to the user?
    Like a JLabel or a text field.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Mar 2013
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: revalidating JPanel when image is deleted from file

    I want it shown on pPanel, which consists of the jsplitpane that has the jscrollpane and the button panel

    & I don't' have a component that shows whether the image is sucessfully loaded or can't find image yet, as of right now I'm just printing it in the command line

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: revalidating JPanel when image is deleted from file

    I don't know if the jsplitpane or jscrollpane classes have any way to display messages.
    Could you add a JLabel or JTextArea where you could display messages?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Mar 2013
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: revalidating JPanel when image is deleted from file

    I can display a JLabel in the bPanel, and it can show the user whether they uploaded the image sucessfully. but my original problem was to show that the image in the jscrollpane has been deleted once the user deletes the image from the file system

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: revalidating JPanel when image is deleted from file

    show that the image in the jscrollpane has been deleted
    Add a message to the component that is used to show messages.
    If you don't understand my answer, don't ignore it, ask a question.

  10. The Following User Says Thank You to Norm For This Useful Post:

    cryslam (April 10th, 2013)

Similar Threads

  1. [SOLVED] Image on JPanel ---> Canvas
    By justyStepi in forum AWT / Java Swing
    Replies: 19
    Last Post: May 8th, 2012, 07:20 PM
  2. Add Image to JPanel
    By bgroenks96 in forum Java Theory & Questions
    Replies: 10
    Last Post: June 16th, 2011, 02:44 PM
  3. Save JPanel as image
    By fahien in forum AWT / Java Swing
    Replies: 1
    Last Post: March 4th, 2011, 08:20 AM
  4. How to copy image from one jpanel to another jpanel
    By ramanavarayuri1986 in forum AWT / Java Swing
    Replies: 0
    Last Post: February 15th, 2010, 02:36 AM
  5. Drawing image on JPanel from another frame
    By jeryslo in forum AWT / Java Swing
    Replies: 3
    Last Post: December 8th, 2009, 04:01 PM