Why the painted content flash and disappear?

I try to run a simple code example from java almanac site but the painted content just flash and disappear. Can any people help to find the reason? Thanks in advance.
Below are the code:
package font;
import java.text.AttributedString;
import java.awt.*;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextLayout;
import javax.swing.*;
public class DrawParagraphDemo extends JPanel {
    public DrawParagraphDemo() {
        this.setPreferredSize(new Dimension(500,500));
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);
        //Create and set up the window.
        JFrame frame = new JFrame("Demo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        DrawParagraphDemo demo = new DrawParagraphDemo();
        frame.setContentPane(demo);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
        demo.drawParagraph((Graphics2D) demo.getGraphics(), "One line of test string", 400);
    public void drawParagraph(Graphics2D g, String paragraph, float width) {
        LineBreakMeasurer linebreaker = new LineBreakMeasurer(
            new AttributedString(paragraph).getIterator(), g.getFontRenderContext());
        float y = 0.0f;
        while (linebreaker.getPosition() < paragraph.length()) {
            TextLayout tl = linebreaker.nextLayout(width);
            System.out.println(tl);
            y += tl.getAscent();
            tl.draw(g, 0, y);
            y += tl.getDescent() + tl.getLeading();
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
}

Hi i have similar problem and i have followed Camickr's suggestion but it looks like my image was still being painted over here's my code
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
* FileChooserDemo2.java is a 1.4 application that requires these files:
*   ImageFileView.java
*   ImageFilter.java
*   ImagePreview.java
*   Utils.java
*   images/jpgIcon.gif (required by ImageFileView.java)
*   images/gifIcon.gif (required by ImageFileView.java)
*   images/tiffIcon.gif (required by ImageFileView.java)
*   images/pngIcon.png (required by ImageFileView.java)
public class Asst4 extends JPanel
                              implements ActionListener {
    static private String newline = "\n";
    private JTextArea log;
    private JFileChooser fc;
     private JPanel display,button;
     JButton load,grey,color;
     private Image image;
     static JComponent newContentPane;
    public Asst4() {
        super(new BorderLayout());
        //Create the log first, because the action listener
        //needs to refer to it.
          display=new JPanel();
          display.setOpaque(true);
          button=new JPanel();
          load=new JButton("Load Image");
          grey=new JButton("Greyscale Image");
          color=new JButton("Color Image");
          load.addActionListener(this);
          //display.setBackground(Color.BLACK);
          //System.out.println("displayable: "+isDisplayable()+" visible: "+isVisible()+" valid: "+isValid());
          //System.out.println("displayable: "+display.isDisplayable()+" visible: "+display.isVisible()+" valid: "+display.isValid());
          display.setSize(500,500);
          button.add(load, BorderLayout.WEST);
          button.add(grey, BorderLayout.CENTER);
          button.add(color, BorderLayout.EAST);
          add(button,BorderLayout.NORTH);
          add(display,BorderLayout.CENTER);
          setVisible(true);
    public void actionPerformed(ActionEvent e) {
               //Set up the file chooser.
               if (fc == null) {
                    fc = new JFileChooser();
                    //Add a custom file filter and disable the default
                    //(Accept All) file filter.
                    fc.addChoosableFileFilter(new ImageFilter());
                    fc.setAcceptAllFileFilterUsed(false);
                    //Add custom icons for file types.
                    fc.setFileView(new ImageFileView());
                    //Add the preview pane.
                    fc.setAccessory(new ImagePreview(fc));
                    //Show it.
               int returnVal = fc.showDialog(Asst4.this,"Load Image");
               //Process the results.
               if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    Toolkit toolkit = Toolkit.getDefaultToolkit();
                    image = toolkit.getImage(file.getAbsolutePath());
                    MediaTracker mediaTracker = new MediaTracker(this);
                    mediaTracker.addImage(image,0);
                    try {
                       mediaTracker.waitForID(0);
                    } catch (InterruptedException ie) {
                       System.err.println(ie);
                       System.exit(1);
               } else {
                    System.out.println("Loading cancelled by user." );
               fc.setSelectedFile(null);
    protected void paintComponent(Graphics g)
          super.paintComponent(g); // this paints the background
          if(image!=null)
          drawImage(image);
    private void drawImage(Image image){
          Graphics2D g=(Graphics2D)display.getGraphics();
          g.drawImage(image,0,0,null);
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
        //Create and set up the window.
        JFrame frame = new JFrame("Compsci_375_Assignment_4");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Create and set up the content pane.
        newContentPane = new Asst4();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        //Display the window.
        frame.setBounds(50,50,500,500);
           //frame.pack();
        frame.setVisible(true);
    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
}Can anyone tell me what's going on and also why if i pack the frame my display panel is disappear?
Thanks a lot

Similar Messages

  • Why does the Apple logo appears and disappears when I'm the iphone 4?

    When I'm using iphone 4 the Apple logo appears and disappears and appears lock screen. What to do? It' s a bug or a hardware problem?

    Hi sarasalves,
    Welcome to the Support Communities!
    If the Apple logo is flashing on your iPhone 4, you may need to put the iPhone in recovery mode so that you can restore it.  The article below explains how:
    If you can't update or restore your iOS device
    http://support.apple.com/kb/ht1808
    I hope this information helps ....
    - Judy

  • I can not attach any files to email or Facebook. When I go to "browse" the window comes up and disappears immediately. I updated browser and Adobe Flash. Restarted computer and zapped pram. any ideas? Please help!

    I can not attach any files to email or Facebook. When I go to "browse" the window comes up and disappears immediately. I updated browser and Adobe Flash. Restarted computer and zapped pram. any ideas? Please help!

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. For instructions, launch the System Preferences application, select Help from the menu bar, and enter “Set up a guest account” (without the quotes) in the search box. Don't use the Safari-only Guest login created by Find My Mac.
    While logged in as Guest, you won’t have access to any of your personal files or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem(s)?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault in Mac OS X 10.7 or later, then you can’t enable the Guest account. The Guest login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode* and log in to the account with the problem. The instructions provided by Apple are as follows:
    Be sure your Mac is shut down.
    Press the power button.
    Immediately after you hear the startup tone, hold the Shift key. The Shift key should be held as soon as possible after the startup tone, but not before the tone.
    Release the Shift key when you see the gray Apple icon and the progress indicator (looks like a spinning gear).
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including wireless networking on certain Macs.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    *Note: If FileVault is enabled under Mac OS X 10.7 or later, or if a firmware password is set, you can’t boot in safe mode.
    Test while in safe mode. Same problem(s)?
    After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of steps 1 and 2.

  • Why did my camera flash and flashlight quit working on iPod 5 I did a complete restore and still nothing only had for a week can't believe it would be broken already

    Why did my camera flash and flashlight quit working on iPod 5 I did a complete restore just to see and still nothing have only had for a week so I can't believe it would be broken already any ideas

    If you restored to factory settings/new iPod via iTunes (Not via Settings>General>Reset>Erase all Content and Setting) and still have the problem that indicates a hardware problem.
    Make an appointment at the Genius Bar of an Apple store..
    Apple Retail Store - Genius Bar

  • Drop Down in ALV Flashes and Disappears.

    Hi All,
    I have a strange issue going on. In an ALV (built on CL_GUI_ALV_GRID) I have got an editable field with a drop down option.Now lets say I have 10 rows in an ALV. I chose an entry from the drop down in one of the rows (this happens OK) and immediately after that I go on a click on drop down for any other row. What happens is that the drop down for the new row that I am in flashes and disappears. Now if I click for the drop down again the drop down appears. Basically whenever an entry is selected in one of the rows, drop down function immediately after that does not work. I have a feeling that it has something to do with the data _changed event but I am not sure how to handle that event.
    I saw a similar thread  [ALV Menu Flash|ALV HANDLE_DATA_CHANGED_FINISHED; but could not figure it out.
    Any suggestions ?
    Thanks
    Anuj

    Hi,
    Let us see the code and check it
    Make the necessary changes at the fieldcatalog
    clear ls_fcat.
    ls_fcat-fieldname = 'COURSE'.
    ls_fcat-col_pos = 5.
    ls_fcat-coltext = 'Course'.
    ls_fcat-outputlen = 10.
    ls_fcat-DRDN_HNDL = 25.
    ls_fcat-edit = 'X'.
    APPEND ls_fcat to lt_fcat.
    and in the class cl_gui_alv_grid we have one method  SET_DROP_DOWN_TABLE
    and it is having one parameter called  iT_DROPDOWN of type  LVC_T_DROP
    generate the internal table and call the method set_drop_down_table
    clear ls_drop.
    ls_drop-handle = '25'.
    ls_drop-value = 'ABAP'.
    append ls_drop to lt_drop.
    clear ls_drop.
    ls_drop-handle = '25'.
    ls_drop-value = 'CRM'.
    append ls_drop to lt_drop.
    clear ls_drop.
    ls_drop-handle = '25'.
    ls_drop-value = 'WEBDYNPRO'.
    append ls_drop to lt_drop.
      CALL METHOD o_grid->set_drop_down_table
        EXPORTING
          it_drop_down       = lt_drop.
    Thanks & Regards.
    Raghunadh.K

  • I CAN'T DOWNLOAD THE FILMS RENTED. THE DOWNLOAD IS STOPPED FAR BEFORE THE DOWNLOAD IS COMPLETED AND DISAPPEAR THE POSSIBILITY TO DOWNLOAD AGAIN

    I CAN'T DOWNLOAD THE FILMS RENTED. THE DOWNLOAD IS STOPPED FAR BEFORE THE DOWNLOAD IS COMPLETED AND DISAPPEAR THE POSSIBILITY TO DOWNLOAD AGAIN

    Hello guys. It seems i'm having the same issue here, but when I open Iphoto it says that I'm not running the latest version. But when I open App Store it doesnt show any updates.
    Does anyone knows why can't I update to Iphoto 9.5? I own the ILife 11 dvd.
    Thanks

  • Screen starts flashes and disappears

    Hello I need help. I am using dazzle to
    broadcast a Sony camera live. Every time I start adobe media live the screen flashes and disappears. It is not running in the back ground either. If i use my webcam it work fine.can some one please help.

    It seems FMLE and Dazzle card are not that friendly to work with each other.
    can you please give us complete details about the card you are using. we can consider this card for certification if it will become popular among FMLE users.

  • "why the Psoft oracle DB and SID names should be in all upper case

    Customer is having a Question like
    "why the Psoft oracle DB and SID names should be in all upper case (according to the PsoftTools 8.50 Installation for Oracle manual)
    why the Peopletools 8.5 install book states all Oracle SID and database names should be in UpperCase.
    If we use lower case database name, would encounter any problems, what sort of problems?
    i Observed that all the Installation manual for 8.49,50,51 States the Same for Creating of Data base !
    Task 1-6-1: Determining Databases and Database Names
    You should also determine the names of the
    databases at this point, using database names that:
    • Are limited to eight characters, all UPPERCASE.
    • Capture information about the PeopleSoft product line and the type of database
    Please suggest on this !
    Thanks
    Bala

    user13798675 wrote:
    Customer is having a Question like
    "why the Psoft oracle DB and SID names should be in all upper case (according to the PsoftTools 8.50 Installation for Oracle manual)
    why the Peopletools 8.5 install book states all Oracle SID and database names should be in UpperCase.
    If we use lower case database name, would encounter any problems, what sort of problems?
    i Observed that all the Installation manual for 8.49,50,51 States the Same for Creating of Data base !
    Task 1-6-1: Determining Databases and Database Names
    You should also determine the names of the
    databases at this point, using database names that:
    • Are limited to eight characters, all UPPERCASE.
    • Capture information about the PeopleSoft product line and the type of database
    Please suggest on this !
    Thanks
    Balabcm@bcm-laptop:~$ env | grep ORA
    ORACLE_SID=v112
    ORACLE_BASE=/u01/app/oracle
    ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
    bcm@bcm-laptop:~$

  • Finder flashes and disappears at top.  Computer dead on only one account.

    My iMac G4 (800 mhz) running the latest update/version of Tiger is suddenly acting up on one account only. On other accounts, no problem. On the problem account, the finder bar appears and disappears about every second. I can start to open applications (Word, Safari, etc.), but they close before fully opening. No recent changes to the computer and only safe internet surfing (to the best of my knowledge).
    My 12-year-old son's homework program is on the account in turmoil. Help, please! Thank you...
    iMac G4 800 mhz   Mac OS X (10.4.5)  

    If you don't mind using the Terminal you can get into any account using super user commands. The slickest, and most dangerous way, is to kill Finder and relaunch it as root. The safest way is to launch Terminal from /Applications/Utilities. Next you want to go into the other user's Prefs folder, so type this and hit the Return key:
    sudo -s
    give your admin password, which is not echoed to the screen, and hit the Return key again. Your regular user name will be changed to root. You can now do whatever you please. Navigate to the other account's Prefs folder:
    cd /Users/otheraccount/Library/Preferences
    hit the Return key, then type ls and hit Return to see a list of all the Preferences. Here's a sample of me accessing that folder in my test account (short name is revelator) and asking for a list of the files:
    Tiger:~ francine$ sudo -s
    Tiger:~ root# cd /Users/revelator/Library/Preferences
    Tiger:/Users/revelator/Library/Preferences root# ls
    From the list of files you can then copy of the name of what you want to remove and paste it in the remove command or type it:
    Tiger:/Users/revelator/Library/Preferences root# rm com.apple.finder.plist
    After you finish removing the files type
    exit
    and hit Return.
    Francine
    Francine
    Schwieder

  • HT202574 what is the difference between Flash and Fusion Drives?

    what is the difference between Flash and Fusion Drives?

    Here's Apple's explanation Mac mini (Late 2012 and later), iMac (Late 2012 and later): About Fusion Drive - Apple Support

  • When I turn it on, the programs open (which i want) but It loads the same content over and over again

    When I turn my computer on, It opens the programs but the same content loads and I can't seem to change it. How can I make it load the most recent previous thing that I did instead of the same thing over and over again?

    try an iOS upgrade to iOS 4.3.5
    if not contatct apple

  • When I use Siri, my screen goes blank and the apple logo appears and disappears. I've reset it, but problem still occurs. How can I fix this?

    When I use Siri, my screen goes blank and the apple logo appears and disappears. I've reset it, but problem still occurs. How can I fix this?

    Did you reset your iPad like this: Press and hold the Home and Sleep buttons simultaneously until the Apple logo appears. Let go of the buttons and let the device restart.

  • I would like to know why the apple devices 5s and mini i pad having trouble finding wifi networks

    I would like to know why the apple devices 5s and mini i pad having trouble finding wifi networks

    That all depends on what troubleshooting steps you've tried.
    What troubleshooting steps have you tried?

  • My BB won't turn on the red light flashes and the key's light up

    Hi
    I have read all posts relating to my problem, but one thing my BB won't do is resgister on my computer.  The phone will not turn on, has the red light flashing and the keys light up, but the screen will not come on.  I have tried taking the battery out, charging it all night, all the recommended/ideas from this sight, but no joy.  I have only had this phone since July last year.  I haven't been able to try updating phone etc as it won't register on my or my husbands computer please help
    Louise

    Hi,
    The way you presented it made me think it had just happened.
    So you have had the phone since July has it ever worked?
    Most likely you are missing some or all of your device OS and you'll need to reload the device.
    Because the phone can't generate enough signal you will have to "force detect it". I've attached the link below. If you want to proceed I'll need what version of Device OS and what version of desktop manager software.
    Thanks,
    Bifocals
    KB10144 How to force the detection of the BlackBerry smartphone using Application Loader
    KB03295 How to verify which version of BlackBerry smartphone software is installed on the computer using BlackBerry Desktop Software
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • Why the video is slow and stutter on the viewer clip?

    Why the video is slow and stutter when I drag the mouse on the cursor to check from left to right?
    I just upgraded to imac 20" and I had never had this problem with my old mac. The old mac seemed to be smoother than this one.
    The only difference was my 1 TB external hardrive is linkup using USB 2.0 this time round since I've not purchased the Firewire 800 yet. Does using USB 2.0 cause this problem?

    I noticed something from my previous iMac. When I drag the cursor from left to right, there is no sound when I'm dragging. Thus, that makes me think that the absence of audio produce smoother flow. How do I disable the audio while I'm working on the viewer then?

Maybe you are looking for

  • Why do threads run one at a time?

    [Newbie] Couldn't get help in another forum, so here goes. Tried this in Netbeans 3.5 then at home later in BlueJ, same thing. Thanks in advance! I have written a small application to play with threads. I create 3 instances of a class and shoot each

  • Deletion material master in bulk

    Hi Friends,       I want to delete some materials (50). I am not going to use those materials further. How could i delete it. I heard we can do archive process to delete that in bulk...so far i have not done that archive process...kindly tell me how

  • ADF BC - view - Control Hints - localization

    I wanted to ask if there is a nice way to create localization of Control Hints based on resource bundle like on UIX page.Is there an easy way to specify the resource bundle which will be accessed by EL? or this must be done other way? (There is not n

  • BW 7.40 with ERP 6.0 without EHP.

    We are planning an upgrade from BW 7.0 to BW 7.40, but the ERP is currently in version 6.0 without EHP, I searched notes related to ERP impact and have not caught anything. Plz any idea? Best regards. HD

  • Counter Problem for Target segments

    Hi All, I am facing a typical problem... Need your valuable inputs.. I have two segments E1TXTP9, E1TXTP8 in the source which will be repeated n times... And Target i have two structure I9INPT00, I9INPT00(this is duplicate subtree) E1TXTP9-->TDLINE i