Small problem with validate()

I have an ArrayList of JPanels in a JApplet. I display the first panel of the array when the applet loads. For traversing through the arrayList i have provided a set of buttons ('first','back','next','last'). When a button is clicked, I remove the currently displayed panel, get the next (or previous) panel from the arrayList and add it to the applet:
public ArrayList arrayOfPanels;
public int sizeOfArrayOfPanels=0,position=0;
public JPanel displayedPanel, buttonPanel;
public JButton firstButton, backButton, nextButton, lastButton;
public void init() {
.......//create array of panels and buttons
buttonPanel.add(firstButton);
buttonPanel.add(backButton);
buttonPanel.add(nextButton);
buttonPanel.add(lastButton);
sizeOfArrayOfPanels=arrayOfPanels.size();
displayedPanel=(JPanel)arrayOfPanels.get(0);
getContentPane().add(displayedPanel);
getContentPane().add(buttonPanel);
public void actionPerformed(ActionEvent e) {
String label=e.getActionCommand();
if(label.equals("Next >")) position=position+1;
else if(label.equals("< Back")) position=position-1;
else if(label.equals("<< First")) position=0;
else if(label.equals("Last >>")) position=sizeOfArrayOfPanels-1;
getContentPane().remove(displayedPanel);
displayedPanel=(JPanel)arrayOfPanels.get(position);
getContentPane().add(displayedPanel);
getContentPane().validate();
if(position==0) {
nextButton.setEnabled(true);
lastButton.setEnabled(true);
firstButton.setEnabled(false);
backButton.setEnabled(false);
else if(position==(sizeOfArrayOfPanels-1)) {
nextButton.setEnabled(false);
lastButton.setEnabled(false);
firstButton.setEnabled(true);
backButton.setEnabled(true);
else {
nextButton.setEnabled(true);
lastButton.setEnabled(true);
firstButton.setEnabled(true);
backButton.setEnabled(true);
My problem is, when i click on a button, the next (or previous panel) does not always get displayed immediately. Only if i minimize the applet and then maximize it, it gets displayed. Though i've included getContentPane().validate(), only the first two times (when i click on the next or last button) a different panel appears, from then on,if i click on a button the applet has to be minimized to view the change. Kindly help me overcome this.

I find that using:
revalidate();
repaint()
works in most situations.
However, you should check out the CardLayout. It was designed for this type of application:
http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

Similar Messages

  • I have a small problem with MSI GF4 MX 420

    Hi,
    I have a small problem with MSI G4MX420-T(S+C) ( MS-8878 ). Exactly with nVidia WDM Video Capture (universal), which  " can't be turned on " by Windows XP.
    I have also new drivers ...
    Could someone help me?
    Asus A7V333
    Athlon 1700+
    128 MB RAM
    Thanks !!!

    If you only have 10 seconds of content in a 15-second composition, then you need to either add more content or shorten your composition.
    You can shorten the composition by changing the duration in the composition settings.
    Since you're obviously very new to After Effects, I very strongly recommend that you start here to learn After Effects.

  • Some small problems with my new 3G iPhone

    Having some small problems with my new iPhone, nothing major, just annoying.
    1. When I plug my iPhone in to charge/sync my Adobe photoshop keeps trying to download the photos on my iPhone, which causes an error message from Adobe that it can't download and it stops all syncing and removes my iPhone from iTunes. I have to unplug and reinsert USB cable and sometimes it works ok and sometimes I have to reinsert again. Also when charging, it will disconnect, reconnect and the samething all over again, photoshop trying to get photos and an error message.
    2. Can't send e-mails via 3G? Only can get, have to connected to a WiFi to send e-mails, or is this normal?

    When your iPhone includes photos in the Camera Roll, it is also detected as a digital camera when connected to your computer, and whichever app you have selected to import photos will automatically launch to import the photos. If you haven't imported these photos, it is a good idea to do so as with any other digital camera. I import the photos followed by deleting the photos from the iPhone after the import process is complete. If I want any of the imported photos available on my iPhone for viewing, I add the photos to an existing album that is selected to be transferred to my iPhone under the Photos tab for my iPhone sync preferences, or add the photos to a new album followed by selecting the album under the Photos tab followed by a sync.
    If your iPhone's Camera Roll does not include any photos that have not been imported, Adobe Photoshop should not launch automatically when your iPhone is connected.
    I know how to disable the selected application for photo import from launching automatically regardless with a Mac, but not with Windows.
    Regarding the sending email problem, who is the email account provider and does the email account provider have an authenticated SMTP server?
    Most ISPs block the use of SMTP servers that are outside of their network or not provided by the ISP being used for your internet connection unless the SMTP server is authenticated. When connected to the internet via AT&T's cellular network, it is no different in this regard. AT&T's SMTP server is included and available by default for use with an email account that does not have an authenticated SMTP server when connected to the internet via AT&T's cellular network, but you probably won't be able to use this SMTP server for sending messages with the account when connected to the internet with your ISP via an available wi-fi network - especially if the email account is provided by your ISP.
    I access two email accounts with the iPhone's mail client and both accounts have an authenticated SMTP server. I've never had any problems sending with either account regardless the ISP being used for an available wi-fi network, or when connected via AT&T's cellular network.

  • A small problem with my Zen Xtra 60 turned into a bigger problem. Help me save it

    What started as a small problem has grown to a big mess. My Zen xtra 60 GB unit started going to "Rebuilding Library" often. With 5000 Wma's on it, this rebuild was taking 30 minutes. So what I attempted to fix with reloading firmware to recognize the new Windows Media Player version, has left me with a dead unit.
    I have followed many of the solutions, that have been able to fix other peoples units, but to no avail. While my computer sees the unit, none of the firmware loads will see the player. I fixed what was said in the register. Went through the 4 options of the "Rescue Mode" on the player, followed several of the knowledge notes on procedures, including hooking unit up to a new Dell Laptop. Exactly the same problem happens on a different computer.
    I guess my first step is to get the computer to see the MP3 player when I run a firmware install.
    Tell me what to do to save my little player.
    Thanks Scott

    peschli wrote:
    . . . if I don't use [my 30GB Zen Xtra] for day, it re-builds my library and half of the songs are disappeared and also so the "memoryplace" . . .
    I've had a similar experience, but to a degree. I've found that if I don't use my <EM>40GB</EM> Zen Xtra for more than one day the player will "re-build" the library... but in my case once the library has been re-built it plays just fine; none of my songs or memory are lost.
    Why does the player have to "re-build" the library if the player is not used for a period of time?

  • Recursive mergeSort... small problem with infinate recursion.

    Basically, I have made a recursive mergeSort method, but there is a small problem...im getting stuck with an eternal recursion, which is obviously followed up swiftly by a stack flow error, problem is I cant see where im going wrong...
    The error reads, "Exception in thread "main" java.lang.StackOverflowError at part3.mergeSort(part3.java:56)"
    Heres the code... any help is highly appreciated, as I am new to java, and this is for university.
    public class part3
        public static void main(String[] args)
          // Declare array of unsorted values.
          int[] values = {1,3,5,7,9,2,4,6,8,10};
          // Display unsorted values on screen.
          System.out.println("Unsorted Values");
          for(int i= 0;i < values.length; i++)
               System.out.println(values);
    mergeSort(values, values.length);
    output(values);
    public static void mergeSort(int[] vals, int n)
    // Declare necessary values
    int lowCount, highCount;
    int[] low, high;
    int i, j, k;
    if (n > 1)
              low = new int[n];
              high = new int[n];
              for(i=0,j=0,k=0; i < n; i++)
                   if(vals[i] < low.length)
                        low[j] = vals[i];
                        j++;
                   else
                        high[k] = vals[i];
                        k++;
              lowCount = j;
              highCount= k;
              mergeSort(low, lowCount);
              mergeSort(high, highCount);
              for(i = 0; i < lowCount; i++)
                   vals[i] = low[i];
              for(i = 0; i < highCount; i++)
                   vals[i+lowCount] = high[i];
    public static void output(int[] data)
    for(int i = 0; i < data.length; i++)
         System.out.print(data[i] + " ");
              System.out.println();

    yes sorry, that was it, when i put that code in my class... i get an acception in thread main...
    heres the code i now have...
    I know i need to add a main method, but im completely unsure of what I need to put inside the main method, if you get what i mean...
    sorry for all the hassle... :(
    public class part3
         * Mergesort algorithm.
         * @param a an array of Comparable items.
        public static void mergeSort( Comparable [ ] a ) {
            Comparable [ ] tmpArray = new Comparable[ a.length ];
            mergeSort( a, tmpArray, 0, a.length - 1 );
         * Internal method that makes recursive calls.
         * @param a an array of Comparable items.
         * @param tmpArray an array to place the merged result.
         * @param left the left-most index of the subarray.
         * @param right the right-most index of the subarray.
        private static void mergeSort( Comparable [ ] a, Comparable [ ] tmpArray,
                int left, int right ) {
            if( left < right ) {
                int center = ( left + right ) / 2;
                mergeSort( a, tmpArray, left, center );
                mergeSort( a, tmpArray, center + 1, right );
                merge( a, tmpArray, left, center + 1, right );
         * Internal method that merges two sorted halves of a subarray.
         * @param a an array of Comparable items.
         * @param tmpArray an array to place the merged result.
         * @param leftPos the left-most index of the subarray.
         * @param rightPos the index of the start of the second half.
         * @param rightEnd the right-most index of the subarray.
        private static void merge( Comparable [ ] a, Comparable [ ] tmpArray,
                int leftPos, int rightPos, int rightEnd ) {
            int leftEnd = rightPos - 1;
            int tmpPos = leftPos;
            int numElements = rightEnd - leftPos + 1;
            // Main loop
            while( leftPos <= leftEnd && rightPos <= rightEnd )
                if( a[ leftPos ].compareTo( a[ rightPos ] ) <= 0 )
                    tmpArray[ tmpPos++ ] = a[ leftPos++ ];
                else
                    tmpArray[ tmpPos++ ] = a[ rightPos++ ];
            while( leftPos <= leftEnd )    // Copy rest of first half
                tmpArray[ tmpPos++ ] = a[ leftPos++ ];
            while( rightPos <= rightEnd )  // Copy rest of right half
                tmpArray[ tmpPos++ ] = a[ rightPos++ ];
            // Copy tmpArray back
            for( int i = 0; i < numElements; i++, rightEnd-- )
                a[ rightEnd ] = tmpArray[ rightEnd ];
    }

  • Small problem with applescript

    Hello Again,
    Every day I use a morning script to launch my programs I have to use... and some more things...
    Aldo I have a problem with Golive.
    When I try to type activate in the editor it makes a bigg A.
    Also with cut and past.
    and when i run the applescript-program it does all I need ( The golive part is at the end... but when I place it in the middle it's just stops.
    I get this fault message : Can't continue <event Coreactv>
    and i guess it has something to do with the A-ctivate
    Is this a bugg? Or can someone explain this?
    I would like to do more after launching Golive..
    tell application "Extensis Suitcase X1"
    activate
    end tell
    tell application "Mail"
    activate
    end tell
    tell application "Adobe Photoshop CS"
    activate
    end tell
    tell application "QuarkXPress Passport"
    activate
    end tell
    tell application "Adobe GoLive CS"
    Activate
    end tell

    Some apps don't respond well to tell blocks. I don't have that app to test, but you could try using something like launch "TextEdit" or tell app "Finder" to open posix file "/Applications/TextEdit.app" to improve your results. Sometimes an ignoring application responses block can help too.

  • I am having a small problem. with Media Go??

    I have a program call " Creative MediaSource Go!" but when click on it to open so i can do some setup, nothing happens. Is ee the hour glass then nothing happens. I already updated with creative. please can some one tell me wat i am missing yo get the "Creative MediaSource Go!" to open and run ??

    Having this problem too: IT'S REALLY REALLY ANNOYING!!! Anyone have an idea how to sort this?

  • Small problems with Image Capture

    Hi,
    When I upload images from my camera, I have a few problems.
    When Image Capture automatically opens, there are two different windows, and I never know which one will open. One has choices like Delete and Eject camera. The other window only has choices like Rotate Right and Rotate Left. Is there a way to get the one with more choices to open every time?
    When I eject the camera (either by using the choice from the one window) or by quitting Image Capture and dragging the camera icon in the Trash, I seem to always get a Device Removal warning when I shut off the camera.
    Thanks,
    Allan

    The second problem may be cured by using 'reformat' of the memory card, in the camera.
    There may be some corruption in the flash memory; or it may be failing.
    The first issue, may be relieved if you can find the correct file plists for Image Capture; and
    trash those preferences. If the actual application is somehow damaged, it may be possible
    to re-install just that application through use of Pacifist (charlessoft, download) to extract
    just that item, from the computer's OS X install/restore disc. Without an 'archive & install.'
    Hopefully someone will have exact details from experience; since I've not had similar issues.
    Usually, I'd use a free image editor such as ToyViewer for Mac; and also Preview, to edit.
    Good luck & happy computing!

  • Small problem with generics

    Hi,
    I'd like to get my generic (Hash)Map back from a textfile, for this I have written a method that reads the file and returns an Object. The only problem I have is that I get the error "java uses unchecked or unsafe operations , ..." with the following code:
    Map<Character, TransVal> thisIsMyMap = (HashMap<Character, TransVal>) readFromFile("filename.dat");I thought it would be the same as parsing a String (guess not :-) ):
    String s = (String) justAnObject;TransVal is a class that contains a BitSet and an Integer.
    Any help plz?
    (btw sorry for my english :-s )

    The reason is that it cannot check, at runtime or at compile time whether or not the cast is valid. It will at runtime check the cast to HashMap (btw, use Map for both the cast and the variable), but it will not check that all the keys are Characters and that all the values are TransVals. What will happen is that somewhere where you actually use the map, if the assumption you are making here is incorrect, there will be a ClassCastException in what appears to be perfectly safe code. If you are positive that your cast is safe, either change the return type of readFromFile or put a @SuppressWarnings("unchecked") annotation on the method and use a java compiler that respects it (eclipse, 1.6, and maybe others, but not sun's 1.5 javac).

  • Small problem with the Nano 6G, and run workouts

    Hello! I have sensor Nike IPod Sport Kit, which is in the new Nano 6G is not needed, because the accelerometer (pedometer) is built into the player and is suitable for running. But buying a heart rate monitor transmitter i is upset that it should only be used with the sensor in the shoe. Because when I connect the transmitter Nike to player Nano 6G, and then connected transmitter heart rate monitor and want to start training, the player Nano 6G is looking sensor in the sneaker, although it could well do without him. Request to developers Apple fix this problem so that you can use the transmitter heart rate monitor with built-in accelerometer in the player Nano 6G.
    Sorry for the google-translator. Regards, Alex.

    Alex, exactly what I was looking for...
    I tryed to get info from Apple and Nike support but seems nobody knows what I'm tolking about.
    I hope Apple will fix it on 6th G even if they'll launch the 7th G.
    Max

  • Small problem with desktop

    When I chose desktop picture from my pictures folder (by clicking on plus and browsing the picture in desktop preferences) it doesn't show previews in some of the folders - it shows empty icons without pictures. I know it's not a major problem but still irritating. Does anyone know why this can be and how to fix it? (when I open same folders with finder everything is shown normally)

    Make sure you have connect the speaker jack in green color out port which is back on the tower.
    Now perform this steps.
    Step1 Changes audio settings in BIOS
    1. To enter the BIOS, turn on the computer and begin pressing the F10  or F1 key
    repeatedly untila BIOS Setup screenopens.
    2. In the BIOS Setup screen, press the F5 key.
    3. Select yesor OK(press the Enter key).
    4. Press the F10 key. Select yes or OK to save the default settings (press
    the Enter key).
    5. Start the computer and check for sound. If there is still no sound,
    continue with these steps.
    6. Use the Left and Right Arrow keys to select the advanced tab.
    7. Find and select the advanced menu items that correspond to audio. This
    may be one of the following:
    8. Onboard Audio, Onboard Audio Options, I/O Device Configuration, On-board
    Sound, Audio Codec
    9.Select either Enabled or disabled depending on the computer configuration
    and press Enter.
    10. Press Enter to save and exit and check for sound.

  • Smaller problem with handling frame-borders in dreamweaver 8

    Hello people
    I have build a website using a frameset in dreamweaver 8.
    Ewerything works fine, except i cannot drag in my frames when i
    re-open the page. I try to select frames in the "windows" bar, and
    click on the different frames to make the frame-border appear, but
    it does not. Only dotted lines that indicate the selected frame
    appear.
    mabe there is a button somewhare that make the draggeble
    borders come back..
    if anybody knows the anwser to my problem - please write.
    Thanks
    Daniel - Copenhagen

    > I have build a website using a frameset in dreamweaver
    8.
    Why? Are you familiar with all the problems associated with
    choosing frames
    for you layout?
    > except i cannot drag in my frames when i re-open the
    page
    Hmm - I don't understand this. You have created a frameset
    page in which
    you define your frames, right? And you have saved both the
    frame pages, and
    the frameset page, right? So, you next open which page? The
    frameset? Or
    the frame page?
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "duranduranduran" <[email protected]> wrote
    in message
    news:glk8uh$noc$[email protected]..
    > Hello people
    >
    > I have build a website using a frameset in dreamweaver
    8. Ewerything works
    > fine, except i cannot drag in my frames when i re-open
    the page. I try to
    > select frames in the "windows" bar, and click on the
    different frames to
    > make
    > the frame-border appear, but it does not. Only dotted
    lines that indicate
    > the
    > selected frame appear.
    > mabe there is a button somewhare that make the draggeble
    borders come
    > back..
    >
    > if anybody knows the anwser to my problem - please
    write.
    >
    > Thanks
    >
    > Daniel - Copenhagen
    >
    >

  • A small problem with a JScrollPane and child windows

    Hi !
    I have created a customized JComponent inside a JScrollPane and when my application starts I create two JTextField's that I put in the JComponent and so far it all works fine to start with, but when ever the JComponent is redrawn after that the JTextField's are overdrawn or at least are not visible any longer...
    Do I need to repaint the sub components of my own JComponent myself or am I doing something very wrong here ?
    a JScrollPane
    a JComponent with some drawing going on in paint()
    a JTextField
    another JTextField
    Mikael

    Ooppps !
    Forget about it, I forgot to put a super.paint( g) at the top of my paint method, that was the problem.
    Mikael

  • 2 Small problems with Inspire 4400 4.1 & SB Surround 5.1 [on Vis

    Hey guys?
    I just bought a Sound Blaster Surround 5. external sound card (USB), which i like to use on my laptop (HP Compaq 6820s with Vista HomePremium), together with my Creative Inspire 4. 4400 speaker set. What i did is; I installed the necassary software from the CD-Rom (for Vista of course), and after installation, I checked if everything worked. It did. I had sound from all my 4 speakers, and i was able to adjust the volume of each speaker (I forgot where that option was located, but thats not important right now). After the installtion, i did the necessary reboot, and i did the recommended software update. This update installed new drivers, but they did something strange; when i click on Creative Audi-center, it says 2. CMSS 3-D. When i click on Creative Audi-console, it says 'headphones' under the speakers. I know thus only have 2. sound
    Right now, i cant change it back to 4.. I know that in the Creative Audio-console, there's an option to 'change' this. But when i change my system from 2. to 4., it doesnt do anything. If i check if I did the right thing, i found out (over n over again, no matter how often i keep changing it), my configuration is still set to 2., no matter how often i change it to 4.. So there's my first problem; i cant set my system to be a 4. system.
    Second problem; i'd like to use the voume control on the SB Surround 5. console for my overall volume. When i remove the wired volume control 6pin DIN cable from my Inspire 4400 subwoofer, my sound wont work. So i still have to use the wired volume control. Also, the volume control on the SB Surround 5. doesnt work (although i can mute the sound with it). Now, al this might be logic, however, hwo is it possible to overcome this obstacle with a DIN cable? My SB Surround 5. system had 9pin DIN in the back, the subwoofer of my Inspire 4400 has a 6pin DIN cable in the back .... what can i do, to configure the volume control on my SB SUrround as my main volume control, in stead of keep using the wired volume control, which is connected to the back of my Insipre 4400 subwoofer?
    Kind regards, and thnx in advance for any help!
    Huub
    PS: When i change my sound setting via Windows' Control panel -> Sound ->? Configure 2- Sound Blaster Li've! 24-bit External-> Quadraphonic sound, i notice that all my 4 speaker work (i checked this via the Test button), but after that, the sound hasnt changed anything when i play my mp3's via WinAmp...
    Message Edited by ThaMaestro on 09-04-2008 04:29 AM

    Hi,
    Are you referring to the Li've! 24 bit External or the X-Fi Surround 5.
    I would recommend getting in touch with support for further assistance on this.

  • Small problem with Chooser

    I'm new to Java and ever more clueless about Swing but am trying to learn.
    I have implemented a chooser to choose a folder. It works but not exactly as I wish. I supply chooser with the last folder that was previously chosen by the user. Chooser displays that folder and other folders in the parent folder. That's OK but I would like the last folder to be "selected" so the user can just accept it and not have to click on it.
    Here's my code:
         chooser = new JFileChooser();
         chooser.setCurrentDirectory(new java.io.File(lastFolderXML.getLastFolder())); // last folder accepted
         chooser.setDialogTitle(choosertitle);
         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
         chooser.setSelectedFile(chooser.getCurrentDirectory());
    How do highlight the last folder accepted?
    TIA
    Nate

    Andrew, thanks for taking time to attempt to help me.
    1 The CODE tag: I looked very hard at the thread to find a code tag but couldn't and was wondering why there was none.Which I why I stated +"reply and quote to see the markup"+ . Did you not read that part either? >o(
    I (...) had no idea that while heading sizes are available on the page the really important code tag is not.Yes, we all hate that, but Oracle doesn't care. That's why we're usually not too harsh on newbies who don't know how to post code, and why the first reply is usually explaining how to do that. We're much less indulgent when newbies disregard this kind advice...
    So far this is the only forum that I've found that does it this way. It would have been very helpful to convey the tag or where it was written up.
    I didn't (...) notice that the acronym SSCCE, which conveyed no meaning to me, was a link.I think I explained what it was too: +"Could you post an SSCCE (a short but complete example that fits in one class, and that (...)"+
    I was about to comment wittily on how one can miss a link, but I have to admit that this forum's rendering is disgraceful and very confusing...
    But I found the problem (...) On Ubuntu it works just as I expected. Next time I have a GUI question I'll specify the OS I'm using.Fine.
    Note that if you had posted an SSCCE, several of us would have run it and testified whether it "worked" for them. Myself, had I tried it, would have replied "It works for me on WinXP. What's your OS?".
    Glad you found it yourself though. Good luck with Java.
    Now to see if I can implement a progress bar.Just in case: in your Swing experiments, make sure you read the Swing tutorial (e.g. for progress bars: http://download.oracle.com/javase/tutorial/uiswing/components/progress.html)

Maybe you are looking for