How to pack() twice without flicker (and other fireworks)? (with SCCEE :)

Hello, there is this "feature", that sometimes you have to call pack() twice to pack tightly around the subject. This has been discussed here before, some people call it a bug, camickr said he did not know why, this is just how the layout worked. OK, the problem with calling it twice, is that the user notices the window flicker.
The flicker does not happen every time (or, better say, we do not see it every time), that's why I put the whole thing in the loop in the SCCEE.
Even worse, this does not happen right now in my program, but in the SCCEE, there is also a boatload of exceptions (not mine), sometimes pack() even called twice does not work, and eventually, the whole loop just hangs.
(So, by Murphy's law, these things will eventually happen in my big program too)
Question: how do I resize a JFrame tightly around a JTextPane, without the flicker (and other special effects)? Here is the code, if you look carefully, you can tell the window momentarily went taller, before going shorter again - does not always happen, if you are lucky it will do this a few times before it hangs altogether... I do this many times in myprogram, as the user moves things around, they really notice.
If I call setVisible(false) before the pack()s and then back to true after, then of course, the flicker is even worse.
Thank you for any suggestion of a workaround... Mark
import java.util.*;
import javax.swing.*;
public class Foobar
     public static void main(String args[])
          JFrame frame = new JFrame();
          JTextPane txt = new JTextPane();
          txt.setText("FOOBAR FOOBAR FOOBAR");
          frame.setContentPane(txt);
          frame.pack();
          frame.setVisible(true);
          while (true)
               try
                    Thread.sleep(250);
               catch (Exception e)
               txt.setText("FOOBAR FOOBAR FOOBAR FOO");
               frame.pack();
               frame.pack();
               try
                    Thread.sleep(250);
               catch (Exception e)
               txt.setText("FOOBAR FOOBAR FOOBAR");
               frame.pack();
               frame.pack();
}Edited by: Mark_Galeck on Dec 16, 2008 3:02 AM

I tidied up your program a little, and you're right - I can see the window size flicker a little. It's very pronounced with only 1 call to pack(), and less so with 2 calls to pack(), but still noticeable.
import java.awt.event.*;
import javax.swing.*;
public class Foobar {
     public static void main(String args[]) {
          SwingUtilities.invokeLater(new Runnable() {
               public void run() {
                    final JFrame frame = new JFrame();
                    final JTextPane txt = new JTextPane();
                    txt.setText("FOOBAR FOOBAR FOOBAR");
                    frame.setContentPane(txt);
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.pack();
                    frame.setVisible(true);
                    Timer timer = new Timer(250, new ActionListener() {
                         public void actionPerformed(ActionEvent e) {
                              long time = System.currentTimeMillis();
                              String text = "Time: " + time;
                              if ((time%2)==0) {
                                   text += " longer";
                              txt.setText(text);
                              frame.pack();
                              frame.pack();
                    timer.start();
}

Similar Messages

  • How can I control my pc and other computers with my ipod touch 5 gen ?

    Hello
    I have recently bought an iPod 5th Generation and I'm very happy with it !! My question is.
    I have an old laptop iBook and it is connected to a hard disk where I stock my music.... So basically, this old computer is my jukebox. The only problem is that the screen on the iBook doesnt work very well (I must press really strong alongside the mousepad in order to see something). So I was wondering if I could control and see (select music and more), from my iPod touch ? Should I absolutely need to have an Apple TV ?
    Is there an APP so I could control my iBook from my Ipod ?
    I also have another laptop (PC) and I was wondering if I could control everything from my ipod touch ? It could be really fun.
    Many thanks, C.

    The is the Apple Remote app that will allow yo to plave your iTunes music via the iPod.
    There aree also apps that allow controllig the entire computer via the iPod. See:
    http://gizmodo.com/5966724/how-to-control-your-computer-with-your-phone

  • HT201363 My iPhone, iPad and iPod are all associated with the same Apple ID.  How can I remove the iPod and associate it with a new Apple ID without affecting the data on the other devices (note: there is no data on the iPod I want to keep)?

    My iPhone, iPad and iPod are all associated with the same Apple ID.  How can I remove the iPod and associate it with a new Apple ID without affecting the data on the other devices (note: there is no data on the iPod I want to keep)?

    Very simple.  Turn off Find my iDevice, then  Tap Settings, General, Erase, Erase all content and settings.

  • How do I transfer my MacBook Air to my wife so she can sync her iTunes account and other settings with her iPad Mini?

    How do I transfer my MacBook Air to my wife so she can sync her iTunes account and other settings with her iPad Mini?

    You can change the account shortname to whatever you wish to use.
    As you can see from my example above. Once you click on the Create User button a new account will be created.
    She will need to get her own Apple ID setup so when she starts with iTunes she can open her own iTunes account unless you both want to share the use of the same Apple ID. This can create a bit of confusion if you have your own iPads or iPhones or iPods. As you have discovered it's pretty much one iDevice with one Apple ID.
    As for the iTunes library that becomes a more complicated issue.

  • How can I attach j-pegs and other documents to an email unopened and stop each them taking up a whole page of my email ?

    How can I attach j-pegs and other documents to an email unopened and stop each them taking up a whole page of my email ?

    In addition to the last poster's suggestion  -  just so you know, it also depends on the email program the recipient uses as to how they will see any attachments - for instance, when I am using my Yahoo Mail, I am absolutely unable to view any attachment within the browser window - Yahoo forces me to download it; there is no way for me to check it (like a preview) to see if I want to download it or not.
    And, FWIW: the window shown in the screenshot does not show on my version of Mail 5.1 (which is the latest for 10.7.2); the only one similar shows when viewing a message received with an attachment, not while sending one. So that must be a different version.

  • How can i hide my sms and other messanger apps?

    how can i hide my sms and other messanger apps?

    No.
    You can delete them.
    You can put a password on the lck screen.

  • I want to email a photo through iPhoto but it says I need a password... I entered my password but it says it doesn't match - what password do they want and how do I fix? (Facebook and other social media iPhoto posts work - just email asking for pass)

    I want to email a photo through iPhoto but it says I need a password... I entered my password but it says it doesn't match - what password do they want and how do I fix? (Facebook and other social media iPhoto posts work - just email asking for password)

    Your email password.
    iPhoto '11: Email your photos
    Open Mac Mail. From the Mac Mail menu bar click Mail > Preferences then select the General tab.
    Make a selection from the:  Default email reader   pop up menu.

  • How do I transfer my photos and other items from the cloude to my Dell desktop

    How do I transfer my photos and other items from the cloud to my Dell
    desktop

    Hello johnfromwildomar,
    Thank you for using Apple Support Communities.
    You can use the following articles to help you set up to share photos from iCloud to your computer.
    iCloud: Set up My Photo Stream
    iCloud" My Photo Stream FAQ
    Regards,
    Jeff D. 

  • How do I get about:config and other about: addresses to drop down from URL bar?

    How do I get about:config and other about: addresses to drop down from URL bar?
    It's a pain having to retype them in full... not sure why there is no easier interface to them.

    hello, you can bookmark the sites for faster access.
    [[How to use bookmarks to save and organize your favorite websites]]

  • How do i transfer my purchases and other songs to my wife's itunes account?

    how do i transfer my purchases and other songs to my wife's itunes account?

    Papou Yorgo wrote:
    Same computer. 2different sign accounts for computer and itunes
    OK.  Sign into yours.  Copy the files either to the Shared files area, or to a flash drive.
    Now sign out of yours and into hers.  Copy the files out of where you put them in the previous step, and into her Automatically Add to iTunes folder, which is found inside the iTunes Media folder.
    Do it the first time with two ro three song files, so you can get comfortable with how it works, before you do the bulk of them.

  • How to find the column name and table name with a value

    Hi All
    How to find the column name and table name with "Value".
    For Example i have value named "Srikkanth" This value will be stored in one table and in one column i we dont know the table how to find the table name and column name
    Any help is highly appricatable
    Thanks & Regards
    Srikkanth.M

    2 solutions by Michaels (the latter is 11g upwards only)...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from cols,
           xmltable(('ora:view("'||table_name||'")/ROW/'||column_name||'[ora:contains(text(),"%'|| :search_string || '%") > 0]')
           columns result varchar2(10) path '.'
    where table_name in ('EMP', 'DEPT')
    TABLE_NAME           COLUMN_NAME          SEARCH_STRING        RESULT   
    DEPT                 DNAME                ES                   RESEARCH 
    DEPT                 DNAME                ES                   SALES    
    EMP                  ENAME                ES                   JONES    
    EMP                  ENAME                ES                   JAMES    
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   SALESMAN 
    EMP                  JOB                  ES                   PRESIDENT
    EMP                  JOB                  ES                   SALESMAN 
    9 rows selected.

  • Once made a selection in photoshop how do you export in Illustrator and use it with a cutting plotte

    once made a selection in photoshop how do you export in Illustrator and use it with a cutting plotter?

    Plotters require continuous paths. Convert the selection to a path and clean it up suitably. Copy&paste it to Illustrator and use it as a clipping mask on your artwork or whatever. You may also need to create a duplicate layer/ separate PDF file file. Talk to the people doing the plotting.
    Mylenium

  • How do i share i tunes and i cloud with 2 iphones

    how do i share i tunes and i cloud with 2 iphones, like when i buy music it will go to my husbands phone or vice versa!

    Sharing an Apple ID for iTunes and App store purchases is not a problem.  Just enter the same Apple ID in Settings>Store>Apple ID.  You can turn on Automatic Downloads here as well.  However, don't share the same iCloud account unless you want to have merged calendars and contacts.  To maintain separation it's best to have separate iCloud accounts with different Apple IDs.  (The Apple ID you use for iCloud does not have to be the same as the one you use for purchases in Settings>Store.)  This article may be of interest: http://www.macstories.net/stories/ios-5-icloud-tips-sharing-an-apple-id-with-you r-family/.

  • How can I share my music and some apps with my children's devices, but not share iMessage

    How can I share my music and some apps with my children's devices, but not share iMessage

    Then only set up your account in "Settings > iTunes & App Stores" and don't give them your password .

  • How you can sync your contact and your mail with iTunes 11 as it's not there anymore ?

    How you can sync your contact and your mail with iTunes 11 as it's not there anymore ?

    ~ means your Home directory. Using the command above takes you to the Home directory on the boot drive.  Your backup files are now on another drive in a directory that used to be your Home but is now a subfolder of Users so you have to specify that drive after the /Volumes, then the user name, then the rest to go there
    I use OSX 10.4.11 and on it the libraries are still visible.  There's two at least.  One general one at the top level of the boot drive and another for each user (the one with the ~).  I think they made at least one of them invisible with newer OS versions.

Maybe you are looking for

  • Loud fan noises when using CD's to install software

    Every time I used a CD to install software or use a program, my CD-ROM drive spins a very high RPM and my fans are really loud. It sounds like the thing is going to blow. It does that the entire time I have it in there. Everything else seems to run f

  • I have a 17 inch Mac book, after migrate to Lion, I take 25 seconds to shutdown. any reason??

    I have a 17 inch Mac book, after migrate to Lion, I take 25 seconds to shutdown. all progams are closed. any reason?? Need I to install a native Lion OS to solve the problem? Regards, José A. Pereira

  • PDF to iDisk - print workflow?

    Hi, Does anyone know if I can add a "save as PDF and send to iDisk" print workflow to the drop down list in the print dialog box? I don't know how to write print workflows, would it be done through automator? Thanks, Adam

  • 10.4.10 Update lowers sound output

    Hi- I know that this is probably on the bottom of the problem list but here it goes: The 10.4.10 update has lowered the output volume on my iMAC. On one volume bar ( and subsequent thereof ) the sound output is significantly less than it used to be i

  • Shipment problem

    We're about to begin loadplanning deliveries from SRLL in TMS. When I send a shipment from TMS into SAP, it fails - Departure point: the location indicates non-existing address LOC$000001 I'm able to send shipments’ from WWTD to SAP without issue. Th