Help request - JFrame re-use problem - Painting issues

Hello,
I'll give a short background on the problem:
The general purpose of my program is to display a series/sequence of screens in a spesific order. I have constructed an object (JFrame) for each of those screens. In the beginning I create a Vector containing information about every screen in the sequence and when the time comes for that screen to appear I use that information to create the screen.
In my first design I created a new object for each screen (I have 6 basic types of screens but they often appear with different data - graphs and tables and such) while after I was done with a screen I released the reference to it. For some reason the memory requirement of that design were immense and kept increasing with each new screen.
To remedy that I switched to a re-usage (recycling sort of say) design. I created a cache of screens, 1-2 of each type depending on whether two screens of the same type may appear one after the other. When a screen appears for the first time, I use the constructor to initialize it and save it in the cache but for future usage I "re-initialize" the old screen with the new data. Only after I finished re-initializng the screen I set it's visibility to true.
Coming to the problem at last: as I understand seeing as the update of the frame's contents finishes before the screen is displayed it should already be displayed in it's updated form, BUT instead it appears with the old data for a split second and then repaints on-the-fly. You can actually see some components disappearing/appearing. This is a pretty nasty visual effect that I cant figure out how to overcome but worst of all I dont understand WHY it happens...
**Edit:* Please read P.S. 3, just to show, this is not because I have a slow computer (it's quite new and has plenty of RAM) and I gave the heap plenty of space so it's not an issue of increasing it with each allocation
I kindly ask for any help/advice on why the problem happens and how to fix it.
Thank you in advance.
P.S. I tried to pipeline the updates, say screen 1 is currently displayed so when the button to move on to screen 2 is pressed, screen 3 is re/initialized and so on. I used a seperate thread but it was synchronized with the displaying method so it should've been just like sequential updates but only less time consuming. When that didn't work I did the sequential update (which I described above) which didn't work either.
P.S. 2. I gave the background in case it might help and to show that an advice of the sort "don't re-use and just create a new object" is out of the question =\
P.S. 3 Something very odd I nearly forgot to mention: I work in Eclipse, and when I run it there I don't encounter this problem, it runs smoothly and there are no such painting problems but when I run it externally from the command line, that's where these problems occur and that is how the program will eventually be used. I don't understand why there is a difference at all, after all the JVM is one and the same in both cases, no? =\
Edited by: Puchino on Dec 24, 2007 10:06 PM
Edited by: Puchino on Dec 24, 2007 10:12 PM

First off, It SEEMS I solved the problem by calling dispose() on the frame once I finished using it, then comes the manual updating and when I set it's visibility to true it no longer does any of weird painting problems it used to. Question is why does it work? I assumeit has something to do with the fact dispose releases the visual resources but could someone please provide a slightly more in-depth explanation?
Second, at the moment my code doesn't have any calls to validate or invalidate or repaint (and I can't call revalidate) because JFrame doesn't inherit from JComponent. So I'd like to know please, which of these methods should I call in case I manually update the frame's contents?
Third, I'll attempt to recreate a short sample code later on today (must be off now).
P.S. Thanks for the replies!

Similar Messages

  • Help! File in use problem when using Swing app

    Hi. I got a program that is pretty much a JFileChooser that prints to standard output the path of the file that I've chosen. If I invoke the DOS command:
    java JFileChooserDemo, I will get the following as expected from the program:
    "You chose a file named: C:\MyJava\Book.xls".
    But if I invoke the following DOS command:
    java JFileChooserDemo > output.txt, the file "output.txt" contains the following:
    "GetModuleHandleA succeed
    LoadLibrary returns baaa0000
    You chose a file named: C:\MyJava\Book.xls"
    So, if I try to open the file or try to modify "output.txt", I get an error message stating that the file is in use.
    What's weird is that, I THINK if I have a program that DOES'NT use Swing or anything GUI-related and prints to standard output with the DOS "> outfile" command, I won't get this problem. So in other words, I can duplicate this problem with a sample Swing application that prints to standard output. Try it yourself.
    In my original program, it does have an event handler that closes the JFileChooser and its container and exits the system via "System.exit(0);", but for some reason, something still has "locked" the output.txt file. I even did the ctr+alt+del and can't find anything that would lock the output.txt file. What's even weirder is that if I run the application again, but output to a different file like "output2.txt", this file is not locked, but the "output.txt" file still is. output2.txt also don't have contain the
    "GetModuleHandleA succeed
    LoadLibrary returns baaa0000" message.
    The only way I know of that would "unlock" output.txt is to re-boot my computer.
    So it seems I have to modify my program somehow because it appears the OS still thinks output.txt file is still in use.
    Someone may think why would I invoke the java interpreter with the DOS "> outfile" command. Well, the reason being, I got a different version of the program that executes a query and I want it to create a delimited text file that contains the resultset of the query, so that I can then import it to Access, Excel, or whatever. But, because of this problem, I can't modify the query result without having to either run the application again and created another file name with the same result or re-boot. Of course, this would be silly.
    Any help in how I can modify my program or any GUI-program so that if I invoke the DOS "> outfile" command, the outfile won't be "locked" would be greatly appreciated. Thanks. If you want my program, you can e-mail me or run any sample program from the Swing Tutorial that prints to standard output and just add the " > outfile" to the java interpreter command.
    -Dan
    [email protected]

    Oops sorry, forgot to add the code. Here it is:
    BTW, can I edit posts? Oh well...
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    public class FileChooserDemo2 extends JFrame {
    static private String newline = "\n";
    public FileChooserDemo2() {
    super("FileChooserDemo2");
    //Create the log first, because the action listener
    //needs to refer to it.
    final JTextArea log = new JTextArea(5,20);
    log.setMargin(new Insets(5,5,5,5));
    log.setEditable(false);
    JScrollPane logScrollPane = new JScrollPane(log);
    JButton sendButton = new JButton("Attach...");
    sendButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser();
    fc.addChoosableFileFilter(new ImageFilter());
    fc.setFileView(new ImageFileView());
    fc.setAccessory(new ImagePreview(fc));
    int returnVal = fc.showDialog(FileChooserDemo2.this,
    "Attach");
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    /** The next 2 lines I added, the rest of the code is original taken from the Swing Tutorial **/
    System.out.println("You chose a file named: " +
                             fc.getSelectedFile().getPath());
    log.append("Attaching file: " + file.getName()
    + "." + newline);
    } else {
    log.append("Attachment cancelled by user." + newline);
    Container contentPane = getContentPane();
    contentPane.add(sendButton, BorderLayout.NORTH);
    contentPane.add(logScrollPane, BorderLayout.CENTER);
    public static void main(String[] args) {
    JFrame frame = new FileChooserDemo2();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.pack();
    frame.setVisible(true);

  • HELP!: File in use problem-"GetModuleHandleA succeed LoadLibrary returns ba

    Hi. I got a program that is pretty much a JFileChooser that prints to standard output the path of the file that I've chosen. If I invoke the DOS command:
    java JFileChooserDemo, I will get the following as expected from the program:
    "You chose a file named: C:\MyJava\Book.xls".
    But if I invoke the following DOS command:
    java JFileChooserDemo > output.txt, the file "output.txt" contains the following:
    "GetModuleHandleA succeed
    LoadLibrary returns baaa0000
    You chose a file named: C:\MyJava\Book.xls"
    So, if I try to open the file or try to modify "output.txt", I get an error message stating that the file is in use.
    What's weird is that, I THINK if I have a program that DOES'NT use Swing or anything GUI-related and prints to standard output with the DOS "> outfile" command, I won't get this problem. So in other words, I can duplicate this problem with a sample Swing application that prints to standard output. Try it yourself.
    In my original program, it does have an event handler that closes the JFileChooser and its container and exits the system via "System.exit(0);", but for some reason, something still has "locked" the output.txt file. I even did the ctr+alt+del and can't find anything that would lock the output.txt file. What's even weirder is that if I run the application again, but output to a different file like "output2.txt", this file is not locked, but the "output.txt" file still is. output2.txt also don't have contain the
    "GetModuleHandleA succeed
    LoadLibrary returns baaa0000" message.
    The only way I know of that would "unlock" output.txt is to re-boot my computer.
    So it seems I have to modify my program somehow because it appears the OS still thinks output.txt file is still in use.
    Someone may think why would I invoke the java interpreter with the DOS "> outfile" command. Well, the reason being, I got a different version of the program that executes a query and I want it to create a delimited text file that contains the resultset of the query, so that I can then import it to Access, Excel, or whatever. But, because of this problem, I can't modify the query result without having to either run the application again and created another file name with the same result or re-boot. Of course, this would be silly.
    Any help in how I can modify my program or any GUI-program so that if I invoke the DOS "> outfile" command, the outfile won't be "locked" would be greatly appreciated. Thanks. If you want my program, you can e-mail me or run any sample program from the Swing Tutorial that prints to standard output and just add the " > outfile" to the java interpreter command.
    -Dan
    [email protected]

    Sure, here it is:
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    public class FileChooserDemo2 extends JFrame {
    static private String newline = "\n";
    public FileChooserDemo2() {
    super("FileChooserDemo2");
    //Create the log first, because the action listener
    //needs to refer to it.
    final JTextArea log = new JTextArea(5,20);
    log.setMargin(new Insets(5,5,5,5));
    log.setEditable(false);
    JScrollPane logScrollPane = new JScrollPane(log);
    JButton sendButton = new JButton("Attach...");
    sendButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    JFileChooser fc = new JFileChooser();
    fc.addChoosableFileFilter(new ImageFilter());
    fc.setFileView(new ImageFileView());
    fc.setAccessory(new ImagePreview(fc));
    int returnVal = fc.showDialog(FileChooserDemo2.this,
    "Attach");
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    /** The next 2 lines I added, the rest of the code is original taken from the Swing Tutorial **/
    System.out.println("You chose a file named: " +
                             fc.getSelectedFile().getPath());
    log.append("Attaching file: " + file.getName()
    + "." + newline);
    } else {
    log.append("Attachment cancelled by user." + newline);
    Container contentPane = getContentPane();
    contentPane.add(sendButton, BorderLayout.NORTH);
    contentPane.add(logScrollPane, BorderLayout.CENTER);
    public static void main(String[] args) {
    JFrame frame = new FileChooserDemo2();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.pack();
    frame.setVisible(true);

  • Help request: "simple" DVD, just pictures, delay issues

    Hi, I admit I'm a newbie regarding DVD authoring, but I'm trying to help a friend who just got her DVD SP 4 and needs to do a simple dvd with some of her paintings and some info about her.
    We've tried to follow the manual's instructions but now I think we need your help!
    So basically we have a project with a menu with 4 buttons (works, bio, cv, contact). No videos involved, it's all pictures based.
    We prepared the pictures in photoshop, and since I read about the slideshow problems in DVD SP, I created a track to show the slides.
    On each subpage (works, bio, cv, contact) I have created also a "button over video", using the subtitle (it's a "menu" word which links back to the menu), it seemed to us the easiest way to create an interaction.
    All the buttons in the project are text, no pics, no videos.
    Everything seems to work fine in the simulator. But when I save it as .img and test in the Apple DVD player, there are some unexpected delays when I click on, for example, the bio, cv, contact menu voices, before these pages to appear.
    It's strange also because these three pages are just made of one picture each at the moment, while the "works" consists of 6 pictures (and it has music also, while the other pages have no audio).
    We have also tried two different methods to build the project: the first version had all the contents on separate tracks (so one for "works", one for "bio", and so on).
    Then we tried with just one track, putting everything on it and using the marker/chapter/jump features to create a correct navigation.
    In this second case the final results are a bit better, but the delay is still there especially on the 3rd and 4th menu voice/chapter of the track ("cv" and "contact").
    Also, it's very annoying that the "button over video"/subtitle button appears before that delayed track/chapter appears, so if you have a tip about this issue too, we would appreciate it!
    Thanks!

    Whilst you are making a simple disc, you are using some advanced features, and for some folk they are just too glitchy to use.
    Here's a suggestion... get all of your images into .pict format at the correct dimensions for your video standard (720x480 or whatever) and number them sequentially. OPen the sequence in Quicktime and allocate five or ten seconds to each image and then save the result out as a piece of dv footage. Bring that in to DVDSP and add chapter markers at the start of each new image, or encode it to MPEG2 and bring it in (If you don't encode, DVDSP will handle that for you, but you might get better results if you do it yourself).
    Create some stories and place the relevant chapter markers into each (works, bio, cv and contact) so that only those markers play. Connect the menu buttons to the story containers (not the markers inside), and set the end jump and menu call for each story to go back to the relevant menu (and button).
    Make sure that your menus are not layer based - use simple overlay style menus or create them from the built in templates and palette items.
    You should then have avoided the slideshow settings in DVDSP and may get better playback performance. Keep in mind that there are always delays when you move from a menu to a track, and these differ according to the DVD player that you are using.

  • Need Help - Custom Identity Assertor using MBenMaker known issue CR207766

    I am facing below WL 9 knwon issue in WebLogic 10. How to resolve it , do I need to create constructor in identity Asserter IMPL classes ? If yes, what goes inside constructor. Pls help as there is no reference for this issue in WebLog release after WL 9. Below is as in WL 9 site at
    http://edocs.bea.com/wls/docs90/issues/known_resolved.html
    CR207766
    The intermediate files that the WebLogic Server 9.0 BETA MBeanMaker generates erroneously includes two types of constructors for you to complete. One type is based on ModelMBean and the other type is based on RequiredModelMBean.
    The constructors that are based on ModelMBean will no longer be generated or supported after this Beta release.
    Workaround:
    When using MBeanMaker to create MBeans for custom security providers, supply content only for the constructors that are based on RequiredModelMBean.

    Not related to the issue. How do you build your project containing provider? Do you use workshop IDE build? Thanks

  • SQ01 help for listing not used problem codegroup and code in notifications

    Hi ,
    I am making a query through SQ01 to find out how many damage codes created for a particular notification type are not being used .
    In infoset I used QMEL which lists problem code group and problem code  and as a bonus we also get codegroup text . When I test this query , I get damage code group and code used in all the notifications . I want solution for the following
    1)How to list only distinct damage codegroup and damage code (Not per notification wise)
    2)Which second table I have to use to get problem code short text
    3)Which table I have to add in infoset and how join has to be created so that I get list of  Damage codegroups and codes not used in notification .
    NPB

    Hi Pete ,
    1)How to list only distinct damage codegroup and damage code (Not per notification wise)
            I have output like
                      problem code group     Problem code grp text        Problem code    Problem code text
                      MRTR                           Transformer  problems        1                        I need table here
                      MRTR                            Transformer Problem           1
                      MRTR                            Transformer problem         2
    I need distinct output like
      problem code group     Problem code grp text        Problem code    Problem code text
                      MRTR                           Transformer  problems        1                        I need table here
                      MRTR                            Transformer problem         2
    2)Which second table I have to use to get problem code short text
                    I need  problem code table
    3)Which  problem code group and code not used
                Suppose for notification type X I have configured damage catalog Q  and Q has MRTR , MRAM , MRGT as code groups and each of them have their own codes (say 1 to 5)...If notifications are created only for MRTR and code 1 , 5
    I need not used output like
    MRTR 2
    MRTR 3
    MRTR 4
    MRAM *
    MRCT *
    How can I achieve this using  sq01,02 etc
    NPB
    Edited by: Narasimha Bhat on Feb 1, 2011 4:54 PM

  • My iPhone 6 ear speaker is not working properly I couldn't able to hear any thing from ear speaker to lissen I had to put on loud speaker or to use handsfree please help me out with this problem if some body have answer?

    My iPhone 6 ear speaker is not working properly I couldn't able to hear any thing from ear speaker to listen I had to put on loud speaker or to use hands free please help me out with this problem if some body have answer?

    Hi Venkata from NZ,
    If you are having an issue with the speaker on your iPhone, I would suggest that you troubleshoot using the steps in this article - 
    If you hear no sound or distorted sound from your iPhone, iPad, or iPod touch speaker - Apple Support
    Thanks for using Apple Support Communities.
    Best,
    Brett L 

  • Can anyone please help me, I'm having problems with sound while watching video clips using flash player using Internet Explorer\

    Can anyone please help me, I'm having problems with sound while watching video clips using flash player & Internet Explorer

    There's a good chance that this is a known issue.  We'll have a Flash Player 18 beta later this week that should resolve this at http://www.adobe.com/go/flashplayerbeta/

  • Hi, when ever I'm using 3G, on my Iphone4 sim stops working and Network is lost, this started after I updated my phone with  6.0.1(10A523)version. Please help how to solve this problem.

    Hi, when ever I'm using 3G, on my Iphone4 sim stops working and network is lost, this started after I updated my phone with  6.0.1(10A523)version. Please help how to solve this problem. Thanks.

    Photos/videos in the Camera Roll are not synced. Photos/videos in the Camera Roll are not touched with the iTunes sync process. Photos/videos in the Camera Roll can be imported by your computer which is not handled by iTunes. Most importing software includes an option to delete the photos/videos from the Camera Roll after the import process is complete. If is my understanding that some Windows import software supports importing photos from the Camera Roll, but not videos. Regardless, the import software should not delete the photos/videos from the Camera Roll unless you set the app to do so.
    Photos/videos in the Camera Roll are included with your iPhone's backup. If you synced your iPhone with iTunes before the videos on the Camera Roll went missing and you haven't synced your iPhone with iTunes since they went missing, you can try restoring the iPhone with iTunes from the iPhone's backup. Don't sync the iPhone with iTunes again and decline the prompt to update the iPhone's backup after selecting Restore.

  • My iPhone 5s was bought with full price in the USA from Sprint, and I was told that it is a global phone. And I can use it in china. But I can not use it in the USA, so could you mind help me to solve that problem.  I think someone of you must help me to

    My iPhone 5s was bought with full price in the USA from Sprint, and I was told that it is a global phone. And I can use it in china.
    But I can not use it in the USA, so could you mind help me to solve that problem.
    I think someone of you must help me to solve this problem !
    Details:
    SN:F2*****FDR
    <Edited by Host>

    See the response in your other thread:
    https://discussions.apple.com/message/24641427#24641427

  • Help with JFrames:Two JFrames dont paint properly

    Hello Guys.I am new here and I would like to ask for some help.
    I have a problem with me Java application.
    My main Class is the MainGUI class which has some selection components and is a JFrame.When the user presses the "proceed" button, it will make a Calculation.class Object to make some calculations.When these are completed, the Calculation class will create a ResultsWindow.class Object which is a new JFrame. The two JFrames (this if type MainGUI and the one of type ResultsWindow) coexist;however they do not show their components properly.What is going on?Can u help me? I am posting some example code:
    public class MainGUI extends JFrame implements ActionListener{
    public MainGUI() {}
    public void actionPerformed(ActionEvent e){
    if (e.getSource() == proceedButton) {
    Calculator calculatorObj=new Calculator();
    if (radioGZIP.isSelected() && radioNone.isSelected()) {
    calculatorObj.applyCalculations("NONE","GZIP",filesTableToProcess,targetFolder);}
    public static void main(String[] args) {
    MainGUI start =new MainGUI();
    public class Calculator{
    public void applyCalculations(String technique,String algorithm,final String[] filesTable,String targetFolder) {
    ResultsWindow resultsWindowObj=new ResultsWindow(technique,algorithm,filesTable,resultTable,resultNCD);
    public class ResultsWindow extends JFrame implements ActionListener{
    public ResultsWindow(String technique,String algorithm,String[] filesTable,String[][] resultTable,double[] resultNCD) { ...}
    I think this is a thread problem...what should I do?The window should repaint everytime I maximize, but it does not...The two JFrames seem to be blocking each other!Help me plz...

    Then, my second stab in the dark is:
    You don't call revalidate() or validate() on some of their containers after
    adding components.
    Post the relevant parts of your code or small example code that can reproduce the problem.
    See: http://www.physci.org/codes/sscce.jsp

  • HT4993 My iPhone 5s was bought with full price in the USA from Sprint, and I was told that it is a global phone. And I can use it in china. But I can not use it in the USA, so could you mind help me to solve that problem.  I think someone of you must help

    My iPhone 5s was bought with full price in the USA from Sprint, and I was told that it is a global phone. And I can use it in china.
    But I can not use it in the USA, so could you mind help me to solve that problem.
    I think someone of you must help me to solve this problem !
    Details:
    <Edited by Host>

    xinyi93 wrote:
    My iPhone 5s was bought with full price in the USA from Sprint, and I was told that it is a global phone. And I can use it in china.
    But I can not use it in the USA, so could you mind help me to solve that problem.
    Yes, the iPhone 5S is a global phone. However, Sprint will only unlock phones for use on GSM networks outside of the U.S. In the U.S., that phone can only be used on Sprint's network.

  • ýesterday  my iphone 5c screen  suddendly  shows connect to itune and i try to restore it using itune but halfway i got a message error occured (14). please help me in solving this problem.

    ýesterday  my iphone 5c screen  suddendly  shows connect to itune and i try to restore it using itune but halfway i got a message error occured (14). please help me in solving this problem.

    what did you learn when you search the internet for iPhone error 14?

  • HT5012 I cannot download the apps as it showing you cannot use the Singapore store u must switch to Indian store. So please help me out in that problem

    I cannot download the apps. It's showing that u cannot use the Singapore software, you must switch to Indian store please help me out on this problem.

    Settings > iTunes & App Stores > tap your Apple ID: > View Apple ID > Country/Region
    If you find that it is set to the correct region, log out of your iTunes Store account, restart your iPhone, and sign into your account again.
    Regards.
    Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Communities page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums and in the Apple Knowledge Base, before you post a question.

  • Pls. need help..i'm using firefox 3.6.10 in windows xp it always crushes while playing farmville please help me to resolve my problem i already disabled some of my adds on but now i cannot totally open any games in face book.

    i'm using firefox 3.6.10 in windows xp it always crushes while playing farmville please help me to resolve my problem i already disabled some of my adds on and i re-install firefox, now i cannot totally open any games in face book. it says you must upgrade your flash player but it is updated. i tried to open it in google chrome and in other browser there was no problem. what should i do? please help me. thanks in advance. GOD BLESS!

    Looks like a problem with the MyWeb Search bar.
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]

Maybe you are looking for

  • Issue with Report

    Hi Friends,   Pls find the issue below           There is a issue with the customer report, When i look at the contracts on R3 - transaction code ME3M - material 34007071 , contract 46.38450 advises contract quantity of 250,759.  when i run a BW repo

  • Error Message with Form Sending

    Hi there, My form is working fine and the PHP is fully functional, however I get this error message once the form has been submitted. Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/va

  • Problem after upsdat

    after ill update my phone i encounter the problem in activating my iphone

  • Intercompany sales process

    Dear ALL SD Guru, I am doing the intercompany sales process . For the same task i have created the sales order , delivery and finally create the invoice for the customer . After that when i am trying to create the intercompany invoice , system is sho

  • Can I leave an iPhone 5c on charge all night?

    Hi, I have recently purchased an iPhone 5C and just have a few questions. Does the phone have to be powered on for the alarm to go off? If so, can I leave the phone on charge all night so my alarm will go off in the morning without causing any harm t