JTextField and JButtons not appearing until clicked.

I'm writing a program to refresh my CS1 java skills. For some reason when I try to add a JTextField and two JButtons to my container they don't appear until Ive clicked them.
Actually more specifically, this only happens after a 100ms wait after setting the frame visible. Any less and the components wind up visible, but scrunched up in the top middle of my frame.
Ive found that if I add the components before and after the wait they are visible and in the correct place, but this makes a noticeable flicker.
I'm running windows vista if that matters.
If someone could help me I would appreciate it.
snippet of code:
public scrollText()
     drawingThread.start();
     mainFrame.setSize(640,160);
     mainFrame.setContentPane(draw);
     mainPane = mainFrame.getContentPane();
     mainPane.setBackground(Color.white);
     mainFrame.setResizable(false);
     mainFrame.setVisible(true);
     try
          Thread.sleep(100);
          addInterface();
     catch(InterruptedException e){}
public void addInterface()
     textInput.setBounds(1,103,501,31);
     play.setBounds(502,103,65,30);
     play.addActionListener(this);
     stop.setBounds(568,103,65,30);
     stop.addActionListener(this);
     mainPane.add(textInput);
     mainPane.add(play);
     mainPane.add(stop);
}

Postings can't be moved between forums. Now you know for the next time.
The general form for building a GUI is
frame.getContentPane().add( yourComponentsHere );
frame.pack();
frame.setVisible( true );Then all the compnoent will show up according to the rules of the layout managers used.
However is you add components to the GUI "after" the GUI is visible then the components are not automatically painted. You need to tell the GUI to invoke the layout manager again so your code would be:
frame.getContentPane().add( componentsToVisibleGUI );
frame.getContentPane().validate();

Similar Messages

  • Components not appearing until clicked

    Hi
    I've made a pool game with textfields for chat with opponents, although the panel with the game in appears fine on the screen, but the panel with textfield, textarea, and scrollbar dont appear until you click on them.
    Anybody got any ideas?

    I'm not sure hopefully you can tell. I'm not too hot on AWT/swing so it could be anything
    <code>
    public class PoolTableGraphics extends JApplet implements MouseMotionListener,MouseListener,KeyListener
    //variables
    class myPanel extends JPanel{
         public void paintComponent(Graphics g){
    class ImagePanel extends JPanel {
    Image image;
    public ImagePanel(Image image) {
    this.image = image;
         public void update(Graphics g)
              paint(g);                                   }
         public void paint(Graphics g)
    //add table & balls etc
    g.drawImage(offscreen.getBuffer(),0,0,this);
    public void init()
    {image = getImage(getDocumentBase(), "pool_table.gif");
         imagePanel = new ImagePanel(image);
         Container contentPane = getContentPane();
         GridBagLayout gridbag = new GridBagLayout();
         GridBagConstraints c = new GridBagConstraints();
         contentPane.setLayout(gridbag);
         contentPane.setBackground(Color.blue);
         c.ipady = 289;
         c.ipadx = 540;
         c.weightx = 0.5;
         c.gridx = 0;
         c.gridy = 0;
         gridbag.setConstraints(imagePanel, c);
         contentPane.add(imagePanel);
         JPanel p=new JPanel(new BorderLayout());
         p.setBackground(new Color(0,0,0));
         text= new JTextField();
         text.setBackground(new Color(255,246,212));
         text.addKeyListener(this);
         text.setBorder(BorderFactory.createLoweredBevelBorder());
         textarea=new JTextArea(100,7);
         textarea.setBackground(new Color(255,246,212));
         textarea.setEditable(false);
            JScrollPane scroller=new JScrollPane(textarea);
         scroller.setPreferredSize(new Dimension(540, 100));
         scroller.setBorder(BorderFactory.createLoweredBevelBorder());
         JPanel label=new JPanel();
         label.setBackground(new Color(247,148,29));
         label.setMaximumSize(new Dimension(540,1));
         p.add(text,BorderLayout.NORTH);
                   //p.add(label,BorderLayout.CENTER);
         p.add(scroller,BorderLayout.SOUTH);
         c.ipady = 90;
         c.gridx = 0;
         c.gridy = 1;
         gridbag.setConstraints(p, c);
         contentPane.add(p);
         setVisible(true);
        setSize(550,500);
         imagePanel.addMouseListener(this);
         addMouseListener(this);
         imagePanel.addMouseMotionListener(this);
         addMouseMotionListener(this);
         offscreen=new BufferedGraphics(this);
    //initialise game variables
    public void paint(Graphics g)
         imagePanel.repaint();//update game area
    //rest of game code
    </code>

  • Letter "A" is appearing on clips and clips not appearing until play pressed

    Hello All,
    Two challenges:
    1. I have the letter A appear on clips when placed in the browser window. This wasn't happening before. Any idea what it means?
    2. When I paste into the browser from the canvas, the clip doesn't appear until I move the head back, and press play. Any idea about this?
    Thanks.
    DG

    Jerry,
    Thanks for the advice. When you mention tutorials on FCP, I assume you mean someplace other than the software package. I say this because I was pretty surprised that it didn't come with some tutorials. Then again, this is for some pretty experienced people, and I'm holding down the other end of the range.
    If the aforementioned is true, could you point me in the direction of some meaningful tutorials at this stage of my experience? I came across a couple, but things like adding a vintage look to my footage is the least of my worries right now. So any links or 3rd party tutorials (Free or Purchase) would be appreciated.
    Cheers,
    DG

  • Since installing iOS 6, I have had problems receiving calls and messages. Calls go straight to answerphone and messages do not appear until I switch off and on again. I have also installed iOS 6.1.1

    Since installing iOS 6, I have had problems receiving calls and messages. Calls go straight to answerphone and messages do not appear until I switch off and on again. I have also installed iOS 6.1.1

    Try a reset. Press & hold the Power and Home buttons simultaneously, ignoring the red power off slider, until the Apple logo appears. Then release both buttons. This should not affect any content on the iPad, it is similar to rebooting your computer.

  • Messages will send to my iPhone and will not appear on my mac until 15 minutes later, how do I fix this so there is not a waiting time?

    I bought a brand new Macbook Air about a month ago, and up until a few days ago whenever I would receive or send a message on my iPhone, it would show up on my Macbook at exactly the same time. Now, a message may come to my iPhone and will not appear in my Macbook messages until 15 minutes or more later. How do I fix this?

    Hello jendur,
    Thanks for the question. After reviewing your post, it sounds like you are still receiving messages on both the iOS device and the Mac it just takes a while. Have you tried signing out and back on the Apple ID in messages on the Mac? I would recommend that you read this article, it may be able to help you isolate or resolve the issue.
    iOS and OS X: Link your phone number and Apple ID for use with FaceTime and iMessage - Apple Support
    Thanks for using Apple Support Communities.
    Have a nice day,
    Mario

  • TS3694 I forgot my password and could not open until it is said "connect to iTunes". I connected to iTunes. for three hours, I restored it. But it is still not restarted. what can I do? I can not use my iPad 3 for three days. Please help me!

    I forgot my password and could not open until it is said "connect to iTunes". I connected to iTunes. for three hours, I restored it. But it is still not restarted. what can I do? I can not use my iPad 3 for three days. Please help me!

    Try and force your iPad into Recovery Mode
    1. Disconnect the USB cable from the device, but leave the other end of the cable connected to your computer's USB port.
    2. Turn off the device: Press and hold the Sleep/Wake button for a few seconds until the red slider appears, then slide the slider. Wait for the device to turn off.
    3.While pressing and holding the Home button, reconnect the USB cable to the device. The device should turn on.
    4. Continue holding the Home button until you see the "Connect to iTunes" screen. When this screen appears, release the Home button. iTunes should alert you that it has detected a device in recovery mode. Click OK, and then click Restore to restore the device.

  • The keyboard sometimes not appearing until restarting, why?

    the keyboard sometimes not appearing until restarting, why?

    Do you use a BlueTooth keyboard? If you do and that keyboard is too close the the iPad the keyboard may not pop up. Turn off the keyboard or turn off Bluetooth if that is the case.

  • My ipod touch go of and will not work untill i plug it back in to a ac power

    my ipod touch go of and will not work untill i plug it back in to a ac power

    You likely have a hardware problem like a dead battery.  To rule out a software problem try the following in order:
    - Reset:
    Reset iPod touch:  Press and hold the On/Off Sleep/Wake button and the Home
    button at the same time for at least ten seconds, until the Apple logo appears.
    - Restore the iPod from backup via iTunes
    - Restore the iPod to factory defaults/new iPod
    If still problem make an appointment at the Genius Bar of an Apple store.

  • The search function in the itunes store does not work.  It will accept a request and suggest searches but then it locks up and will not search.  Clicking on the magnifying glass or a suggested search does nothing.  Re-installing itunes has not helped.

    The search function in the itunes store does not work.  It will accept a request and suggest searches but then it locks up and will not search.  Clicking on the magnifying glass or a suggested search does nothing.  Re-installing itunes has not helped.

    everything you stated here is exactly what i have done and have got nowhere. i have windows 7 64 bit on a hp 8 g of ram desktop. im also looking for help

  • How to get a question in the course placed anywhere in the course and does not appear in the quiz result or total number of questions. Pretest would work except it can't go anywhere in the course (at least for me it can't)

    How to get a question in the course placed anywhere in the course and does not appear in the quiz result or total number of questions. Pretest would work except it can't go anywhere in the course (at least for me it can't)

    Use a normal question, and do not add the score to the total score. That will give you a correct score at the end. But the total number of questions, that system variable will still take into account all questions. You'll need a user variable, and calculate its value by subtracting 1 from the system variable cpQuizInfoTotalQuestionsPerProject. Same for the progress indicator if you want to show it?
    Customized Progress Indicator - Captivate blog
    If you want to allow Review, you'll have to tweak as well. You didn't specify the version, and all those questions I now mentioned.
    And my approach, since you talk about only one question: create a custom question, because you'll have total control then.

  • IPAD Mini Locked after iOS upgrade, tried reset on iPAD did not work, plugged in and device not appearing in iTUNEs for reset/restore

    PAD Mini Locked after iOS upgrade, tried reset on iPAD did not work, plugged in and device not appearing in iTUNEs for reset/restore.  Just get an Apple Logo then a flashing blue screen as if it is caught booting up.   This has happened twice before and iTunes restore fixed it.  But this time device not appearing in iTunes.
    Running iTunes for PC.  But as stated restore has worked before!  Any help greatly appreciated!!

    Place the device in DFU mode and let iTunes restore the device to factory condition.

  • I preordered One Direction's new album Midnight Memories, but did not purchase it. It is not in my downloads or purchases even though it says it's purchased. I can't even buy it because it says purchased and will not let me click the button. Please help!

    I preordered One Direction's new album Midnight Memories, but did not purchase it. It is not in my downloads or purchases even though it says it's purchased. I can't even buy it because it says purchased and will not let me click the button. Please help!

    Try:
    HT2519 Pre-ordered album, it says...: Apple Support Communities

  • I updated the system to OS X Mavericks and now I cannot open iPhoto with all my pics in. I trying to update iPhoto and  this note appears: "Update unavailable with this Apple ID"

    iMac OS X 10.9.4
    3.06 GHz Intel Core 2 Duo
    4 GB 1067 MHz  DDR3
    I updated the system to OS X Mavericks and now I cannot open iPhoto with all my pics in.
    I trying to update iPhoto 9.5.1 and this note appears:

    Make sure you're logged in to the App Store with the same Apple ID that you used to download and install Mavericks.  If necessary, log out of the App Store and log back in.
    If that fails  contact the App Store support personnel via the link circled in this screenshot:

  • (com.apple.collabd[15483]): Service setup event to handle failure and will not launch until it fires.

    Hello,
    I am fairly new at Xserve administration, but I got thrown in the fire and i need your help.
    My system.log is being hammered with this error:
    (com.apple.collabd[15483]): Service setup event to handle failure and will not launch until it fires.
    I did my research and it seems to be related to Wiki, but I disabled wiki and restarted and it is still coming up. Any advice would really help
    System Version: OS X 10.10.1 (build 14B25)
    Server Version: Server 4.0.3 (Build 14S350)

    Try deleting the preferences file

  • SOMETHING IS WRONG, I SEND A FILE TO TRASH AND DOES NOT APPEAR IN TRASH, THE TRASH IS EMPTY

    SOMETHING IS WRONG, I SEND A FILE TO TRASH AND DOES NOT APPEAR IN TRASH, THE TRASH IS EMPTY

    I had the same problem. It was solved see the discussion at  https://discussions.apple.com/message/19433909#19433909

Maybe you are looking for

  • Moving from Windows Lap Top to Mac Book Pro, i gotta do it ......

    My missus dragged me into an Apple Store yesterday, she is itching to get an iPad2, the rest of the store was full of Mac computers, they are so LOVELY and so easy to use, beautifull in every way, so for £1500 + i can get a MacBookPro, but how much o

  • Monitoring OAQ using mgw_gateway gives an odd result?

    When we submit the following query: select  AGENT_STATUS, AGENT_PING, LAST_ERROR_DATE, LAST_ERROR_TIME from mgw_gateway; We get this result: SQL> select AGENT_STATUS, AGENT_PING, LAST_ERROR_DATE, LAST_ERROR_TIME from mgw_gateway; MESSAGING GATEWAY IS

  • Forrester Report on Information-as-a-Service - BEA Systems Leads

    Forrester has published a report on Information-as-a-Service which included AquaLogic Data Services Platform. The sub-title reads "BEA System Leads, With IBM, Oracle, And Red Hat Following Closely". The complete report is available for purchase from

  • Comma without preceding colon (after SELECT ?)

    Hi, I'm rather new to ABAP and only know some basics, and I ran into an error that I can't solve, must be something stupid: The error is: Comma without preceding colon (after SELECT ?) and this is the code that seems to cause this error:     LOOP AT

  • Use Native iOS/Android APIs with Flex/Flash Builder 4.5.1?

    Is there any documented, official  way to access the native APIs on mobile devices (iOS and/or Android,  specifically)?  Perhaps some sort of ExternalInterface support?  My most  important need for this is importing 3rd party SDKs, the first one  bei