Rudimentary photo browser... trouble with repaint

Hi folks,
I'm working on a simple little practice app that allows browsing of photos by clicking on two buttons ("next pic" and "previous pic"). I'm having a problem with the JPanel in which I'm trying to display my photos. Whenever my buttons fire the changePic method, I see the new photo, but it is drawn over the previous photos (i.e. they are not erased). Could someone please advise me on how to keep this from happening. Also, how would I go about making each image (regardless of size) centered in the JPanel?
public class PhotoPanel extends JPanel {
     Image image;
     public PhotoPanel (Image aImage) {
          image = aImage;
    public void paint(Graphics g) {
        g.drawImage(image, 0, 0, this);
     public void changePic(Image aImage) {
          image = aImage;
          this.repaint();
}Thanks!

Swing related questions should be posted in the Swing forum.
There is no need to override a JPanel for this. Simply add a JLabel to a panel and the use setIcon(...) when you want to change the image.

Similar Messages

  • Troubles with Repaint/Revalidate and all...

    Alrighty, I've wasted far too much time trying to track this down myself when I am sure someone can answer it in a couple lines. The root of the problem lies in this whole blasted revalidate and repaint thing.
    I have read numerous threads in here, and they all seem to talk about the opposite problem I am having. I am really very frusterated with this ATM, so I'm hoping someone can help out.
    Here is the basic feel of my project:
    JFrame
    JTabbedPane
    Tab1
    JPanel left
    JPanel right
    The left panel contains a scrolling pane, inside of which is a panel (BoxLayout along YAxis) that gets labels added to dynamically. Data from a database is used to create the labels.
    On the right panel I have textboxes for dataentry and a button. When the button is pressed, the data from the boxes is placed in the database, and a method is called to refresh the left scrollpane. Here is that code:
    private void populateVendors() {
        vendorlist = IMS.vdv.retrieveVendors();  //This is of type String[][]
        JPanel panel[] = new JPanel[vendorlist.length];
        for(int i=0; i<vendorlist.length; ++i) {
          panel[i] = new JPanel(new BorderLayout());
          panel.add(new JLabel(vendorlist[i][1]),BorderLayout.CENTER);
    panel[i].setBounds(new Rectangle(0,20*i,250,20));
    panel[i].setName(vendorlist[i][0]);
    panel[i].addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e){
    VendorPanelClicked(e);
    public void mouseEntered(MouseEvent e){
    VendorPanelEntered(e);
    public void mouseExited(MouseEvent e){
    VendorPanelExited(e);
    pnlVendorList.add(panel[i],null);
    This code refreshes the scrollpane (pnlVendorList is the panel inside of the scrollpane) just as I want it to. But only until I move my mouse over the panel that just changed (invokes the mouse entered event), or until I switch tabs and come back. Basically the next time this panel gets repainted, it reverts back to the old data.
    I am sure this is clear as mud, so if you need clarification ask. Otherwise I would realy like some help with this!
    Thanks in advance.

    Do you remove the old components from pnlVendorList?
    private void populateVendors() {
      pnlVendorList.removeAll();
      pnlVendorList.setLayout(new GridLayout(0, 1));
      vendorlist = IMS.vdv.retrieveVendors();
      for(int i=0; i < vendorlist.length; i++) {
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(new JLabel(vendorlist[1]),BorderLayout.CENTER);
    panel.setName(vendorlist[i][0]);
    panel.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    VendorPanelClicked(e);
    public void mouseEntered(MouseEvent e) {
    VendorPanelEntered(e);
    public void mouseExited(MouseEvent e) {
    VendorPanelExited(e);
    pnlVendorList.add(panel,null);

  • Browser troubles with newly installed Tiger

    Since installing 10.4.6, I'm having trouble getting to most websites with any of the browsers on my machine. This includes Safari, Camino, and even Internet Explorer 5.2. The problem is not consistent, as I will get an error message several times, and then get through (sometimes). An example of the error mesages:
    Google Error
    Not Found
    The requested URL /exchange/ was not found on this server.
    My ISP (Earthlink) suggested I delete all cookies containing earthlink.net, which did not solve the problem. I tried deleting all cookies, which still did not solve the problem. I don't know if it's a compatibility problem between the browsers and the OS, between Earthlink and the OS, or what. Help!

    Intermittent sounds like Hardware, but try trashing the "/Users/nnnn/Library/Preferences/com.apple.internetconnect.plist" for a start.

  • Browser troubles with iWeb 1.1.2

    I've been developing a website with iWeb 1.1.2 for a client. I'm using hostmonster.com to host my domain because I don't have a mobile Me account. Because of this, I'm using FTP to publish my website to hostmonster. I've published it and uploaded all of the files to the FTP file manager. Now when I visit the actual website using safari or firefox, none of the links from the homepage work. I checked the source code, and I can't figure out anything that could be wrong. But when I visit it using Internet Explorer, the entire website works. So is there any way I can fix this so that it works with all browsers (or at least all of those three)?
    here's the address in case anyone can find anything wrong with the code:
    www.maryboucher.com

    Intermittent sounds like Hardware, but try trashing the "/Users/nnnn/Library/Preferences/com.apple.internetconnect.plist" for a start.

  • I have a new MacBook and I'm having trouble with the help section. I would like to rearrange the order of my photos with in an Event, how do I do this? I follow the directions but it will not work. Thanks for some tips.

    I have a new MacBook Pro and I'm having trouble with some of the Help sections. I want to rearrange the order of my photo's within an Event. I have followed the directions but it will not let me do it, what am I missing?  Thanks for any tips.

    Are you talking about iPhoto? If you are please post this in the iPhoto forum, thanks!

  • HT201496 Hai there. I am facing trouble with my garageband apple loops.i don't see apple loops in my browser since quite some time i don't know what has happened to it and how it happened . i just wanted to learn some of basic things about music.can you h

    Hai there. i am having a trouble with the garage band apple loops to get into my macbook pro. . i had it some time back and i dont know where it has gone and how it get it back. is there anyone to help me to get the loops back into the browser . i will be grateful to you if some one can help me with it/ thanks.

    First check, if you do not accidentally have hidden or filtered your loops:
    Uncheck the "Filter for more relevant results" option in the Audio tab of the GarageBand Preferences.
    And the drop down menu on top of the Loop Browser should be set to "Loops", not to some Jam Pack or other collection.
    If you still don't see any loops, check if you have set your project to a special signature, like 9/8, for that no standard loops do exist.
    Then check, if any loops actually are installed in your system Library: Depending on your GarageBand version you should find the standard loops in the Audio folder of your system Library (Application Support > GarageBand):
        Your System Drive > Library > Audio > Apple Loops
    If the Loops are installed, but GarageBand does not show them, you need to rebuild your Apple Loops Index: See the FAQ for how to do it:
    Re-Index GarageBand's Loops
    This requires two steps:
    erase the old Apple Loops Index by deleting everything in
    Your System Drive > Library > Audio > Apple Loops Index
    and then rebuilding the Loops Index by dragging the folder containing all of your loops onto the Loop Browser in GarageBand.
    If no Loops are installed in your Library, you will have to restore them from your Backup.
    Regards
    Léonie

  • Trouble with Adobe Bridge CS5.5 for Mac Lion Photo downloader

    Hi, I am having trouble with  CS5.5 Bridge's photdownloader when I am trying to choose a folder location.
    Im using Lion / Mac
    When I try to choose say an external drive or another folder location it will freeze up and stay on "Choose" the button flashes on and off but when i try to click it it will not respond or select the desired file location
    The photodownloader does not respond to any other commands..i have to force quit it..yes i have re-booted..re-started and problem remains..
    The only way i can download photos is by choosing the first file option of the pictures file on my harddrive which is not want I wish to do..i have noticed that this started happening after the Raw update..was wondering if this is affecting Photodownloader..
    any suggestions would be greatly appreciated..thank you

    Thank you, SG, for clarifying which OS's this will work with.
    I agree with Jennie - the beauty of "get photos from camera" is that it takes 2 steps out of the workaround you mention above. Personally, I'm okay living with 6.4.1, as I have an older camera. I won't be happy if one of the push updates re-updates me to 6.5 though. I wouldn't want to redo the reinstallation of the new version. This method will not work for any of my clients or students though - they normally can't comfortably follow the technicality of downgrading, and some have newer cameras and would need the 6.5 version. (I don't believe in betas for my clients, and neither do they, for the most part)
    I guess I should thank Adobe - some of my clients have needed tech support to perform the downgrade (SO many people aren't comfortable technically), and some of my clients needed to be retaught the workaround SG mentions. Adobe's flub has actually made me a little money - which I'd rather not have to make this way.
    SG's workaround does work and makes sense - but for my clients with hundreds of images at a time, who have to rename items, add copyright info, & etc., this more than doubles their work-time for the start of their workflow. I hope Adobe gets that GM version out soon.
    BTW - this issue supports an argument I've hadfor years regarding "PUSH" updates. I always tell my clients and students not to do them until they research the update. Because of what I do, I do have to install them personally, but I'm grateful I'm comfortable fixing things myself.

  • I'm having trouble with the develop module in LR5.4. Any adjustments are taking effect, but only viewable in the filmstrip, not on the main photo. The navigator will go grey, as does the main area too. This applies to all edits done in develop module. I h

    I'm having trouble with the develop module in LR5.4. Any adjustments are taking effect, but only viewable in the filmstrip, not on the main photo. The navigator will go grey, as does the main area too. This applies to all edits done in develop module. I have posted several times on the forum with no responses to address this, and have seen others with the same issue. I have even gone as far as to do a complete re-install of LR5, with no success. I'm at a loss, and I depend on it for so much editing. Please help.

    Reset your preferences file: Resetting (or 'Trashing') the Lightroom Preferences file - Lightroom Forums
    Report back if that doesn't work.

  • IPhoto: trouble with sending photos via gmail.

    For some reasons, for about one or two months ago start having troubles with sending photos from iPhoto via gmail.
    It used to work perfectly, but now refuses to send photos. Pop up message says that there are some trouble with accessing accounts.
    Once I restart my computer it works well again.

    Hello ilya,
    In Mail's Window Menu, choose Connection Doctor, any red dots for status, if so what is the message?
    Then click the Show Details button & Check again.
    Mail: Can't send messages, "Cannot send message using the server smtp.xxxxx.com" alert appears...
    http://support.apple.com/kb/TS1482

  • Trouble with browser editing FTP upload

    I have been updating a site to a sub-domain of my personal site while working for client. Yesterday when I tried to walk them through the in-browser editing feature I got an error that wouldn't let me login to edit the site. I followed all of the instructions in the error message (use the "upload via FTP" setting, sign in with the same user) but I still can't log in. Is this a bug with how Muse handles sub-domains, or what else am I doing wrong?

    No, everything uploaded correctly. You can see my site properly  
    -Eric
    On August 23, 2014 at 3:37:13 PM EDT, Zak Williamson (Adobe) <[email protected]> wrote:      Trouble with browser editing FTP upload    reated by Zak Williamson (Adobe) in Help with using Adobe Muse CC - View the full discussion   When using File > Upload to FTP Host... do you receive a warning message that the domain name could not be validated?    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at https://forums.adobe.com/message/6668001#6668001  Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:   To unsubscribe from this thread, please visit the message page at . In the Actions box on the right, click the Stop Email Notifications link.   Start a new discussion in Help with using Adobe Muse CC by email or at Adobe Community  For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • E-Mailing Photos from iPhoto - Having trouble with resolution

    I am having trouble with emailing pictures from i-photo. When I email pictures as attachments they end up being low resolution versions and the receiver can not print them. I can not figure out what sort of setting I must have set. Please help.

    MMVP
    Welcome to the Apple user assistance forums
    1 - how are you selecting and attaching the photos?
    2 - what is the resolution of the photos in iPhoto?
    3 - if you are using the iPhoto e-mail capability (recommended) you select a photo(s) and click mail - there you can choose actual, large, medium or small
    4 - this creates an e-mail message in the e-mail client of your choice (iPhoto preferences) - if you are using Apple mail in the lower right hand corner under the e-mail there is a menu where you can set Actual, large, medium or small
    Be sure that both selections are set the way you want them - if either is se tto small you will send a small (low resolutin) photo
    LN

  • I'm having trouble with my iCloud photos. I thought i could be a little sneaky and take a photo of my photos that were more than 30 days old, so they would be uploaded along with my new photos. that part worked, but i can't upload them to Snapfish?!

    i'm having trouble with my iCloud photos. I thought i could be a little sneaky and take a photo of my photos that were more than 30 days old, so they would be uploaded along with my new photos. that part worked, but i can't select them to upload them to Snapfish?! Any thoughts? I'm bummed. I've got a few hundred photos on my iPhone that I'd like to move seemlessly - or somehow at all.

    hopefully something in here is helpful?
    http://support.apple.com/kb/HT4486

  • I am having trouble with the Canon Image browser ex.l

    i am having trouble with the canon image browser ex.After sevearl downloads i eventually got past the 80% mark.it is now downloaded.however as soon as I click on it it opens up and then a message comnes upm saying that there is a problem and windows is searching for the problem.it then closes the oprogramme down..Any help would be appreciated 

    I am having the same problem and have contacted Canon, they've answered me several times with things to try but nothing they've told me to try helps. It looks like they are going shrug, scratch their heads soon and  pass the buck to Microsoft or HP my comp make .
    I have a Windows 8.1 OS, 64 bit comp.

  • Hi having trouble with camera roll photos - can not see them in i tunes

    Hi having trouble with camera roll photos - can not see them in i tunes. Is adobe photoshop the only program I can use?

    You don't see them in iTunes. In theory your computer should see the device as a camera and you should be able to transfer the photos in the same way as if you'd connected a 'proper' camera to your computer (this only applies to photos taken with the device or saved from emails/websites etc, it doesn't apply to photos that were synced from your computer). There is some help/guidance in this article for transferring photos to your computer : http://support.apple.com/kb/HT4083

  • Has anyone had trouble with photo albums after downloading a newer version of iPhoto?

    Has anyone had trouble with photo albums and viewing photos after downloading a newer version of iPhoto?

    I downloaded mountain lion and then iPhoto '11 in order to tap into iCloud capabilities with all of my devices. (My Mac was outdated in regards to operating platform to do this). After installing iPhoto 11, I had to repair and rebuild my library of photos.  However, after doing this, all of my albums were jumbled and, while I can see the image thumbnail, when I click on the thumbnail, and error that looks like a black triangle and gray exclamation pops up as opposed to the larger hi def image I want to view.

Maybe you are looking for