Help Refreshing JFrame, Validate not working...

Hi,
I've read many post suggesting that calling the JFrame.getContentPane().Validate() should refresh my JFrame and display the modifications made to the components on it, but it doesn't work for me. OK, so i'm creating a login screen where i want to hide 2 combos/2 labels, move the buttons and resize the frame when i click on a button (similar to the Windows Login screen where you can click "Options" to view the Domain Combo). When I hide my comtrols, works perfect, when i want to re-display them, the section of the frame that was hidden does not refresh what was behind it. The Option Button calls the ButtonOptionHandler() function, that's where the Validate() is executed.
Here is the complete code for easier understanding, you can run it and see the effects:
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.ImageIcon;
import java.awt.event.*;
public class screenLogin extends JFrame implements ActionListener {
private static String OK = "OK";
private static String CANCEL = "Cancel";
private static String OPTION = "Option";
private boolean showODBC = false;
     private JLabel lblUser;
     private JLabel lblPass;
     private JLabel lblOraODBC;
     private JLabel lblSqlODBC;
     private JTextField txtUser;
     private JPasswordField txtPass;
     private JComboBox cboOraODBC;
     private JComboBox cboSqlODBC;
     private JButton btnOK;
     private JButton btnCancel;
     private JButton btnOption;
     private JLabel lblImage;
     public screenLogin() {
          InitUI();
     private void InitUI() {
          this.setSize(400,230);
          this.getContentPane().setLayout(null);
          /* Labels */
          lblUser = new JLabel("NorLims User", SwingConstants.RIGHT);
          lblPass = new JLabel("Password", SwingConstants.RIGHT);
          lblOraODBC = new JLabel("Oracle ODBC", SwingConstants.RIGHT);
          lblSqlODBC = new JLabel("SQL Anywhere ODBC", SwingConstants.RIGHT);
          lblUser.setBounds(10, 65, 120, 23);
          lblPass.setBounds(10, 90, 120, 23);
          lblOraODBC.setBounds(10, 115, 120, 23);
          lblSqlODBC.setBounds(10, 140, 120, 23);
          txtUser = new JTextField();
          txtUser.setBounds(140, 65, 100, 20);
          txtPass = new JPasswordField();
          txtPass.setBounds(140, 90, 100, 20);
          txtPass.setEchoChar('*');
          cboOraODBC = new JComboBox();
          cboOraODBC.setBounds(140, 115, 200, 20);
          cboSqlODBC = new JComboBox();
          cboSqlODBC.setBounds(140, 140, 200, 20);
          btnOK = new JButton("OK");
          btnOK.setSize(80, 25);
          btnOK.setActionCommand(OK);
          btnOK.addActionListener(this);
          btnCancel = new JButton("Cancel");
          btnCancel.setSize(80, 25);
          btnCancel.setActionCommand(CANCEL);
          btnCancel.addActionListener(this);
          btnOption = new JButton("Options");
          btnOption.setSize(80, 25);
          btnOption.setActionCommand(OPTION);
          btnOption.addActionListener(this);
          // position Buttons and display labels/combos
          ButtonOptionHandler();
          // I commented this part since you dont have the login.jpg
          //lblImage = new JLabel(new ImageIcon("login.jpg"));
          //lblImage.setBounds(0, 0, 400, 60);
          this.getContentPane().add(lblUser, null);
          this.getContentPane().add(lblPass, null);
          this.getContentPane().add(lblOraODBC, null);
          this.getContentPane().add(lblSqlODBC, null);
          this.getContentPane().add(txtUser, null);
          this.getContentPane().add(txtPass, null);
          this.getContentPane().add(cboOraODBC, null);
          this.getContentPane().add(cboSqlODBC, null);
          this.getContentPane().add(btnOK, null);
          this.getContentPane().add(btnCancel, null);
          this.getContentPane().add(btnOption, null);
          //this.getContentPane().add(lblImage, null);
     public void actionPerformed(ActionEvent e) {
          String cmd = e.getActionCommand();
          if (OK.equals(cmd)) { //Process the OK Button
               ButtonOkHandler();
          } else if (CANCEL.equals(cmd)) {
               ButtonCancelHandler();
          } else if (OPTION.equals(cmd)) {
               ButtonOptionHandler();
     private void ButtonOkHandler() {
          System.out.println("OK Button");
     private void ButtonCancelHandler() {
          System.out.println("Cancel Button");
          System.exit(0);
     private void ButtonOptionHandler() {
          showODBC = !showODBC;     // Toggle the value
          int top = (showODBC ? 165 : 115);          // determine the top for the buttons
          this.setSize(400, (showODBC ? 230 : 180));
          lblOraODBC.setVisible(showODBC);
          lblSqlODBC.setVisible(showODBC);
          cboOraODBC.setVisible(showODBC);
          cboSqlODBC.setVisible(showODBC);     
          btnOK.setLocation(100, top);
          btnCancel.setLocation(180, top);
          btnOption.setLocation(260, top);
          this.getContentPane().validate(); // This dont refresh ?!?
I hope someone can help me with this!
Thanks,
XiNull

First suggestion would be to use a layout manager. Then changing the visibility of components within the layout mgr will cause all the proper resizing, refreshing, etc. to happen for you. You should never have to call validate on your own like that (unless you are doing something really bizarre, which you aren't). Generally null or XY layout managers are more hassle than they are worth (and a maintenance nightmare). Do yourself a favor and learn to use gridbaglayout, etc. While a bit wacky to get used to, you will be glad you spent the time on it.

Similar Messages

  • F4 help for 0MAT_SALES is not working in BI 7

    Hi Gurus,
    The F4 help for 0MAT_SALES is not working when distibution channel is selected as (!=02) in Bex Analyzer. But for all other values for distibution channel  i am getting values in F4 help.
    Since 02 is excluded it is supposed to give values for all other combination. but it not so.
    Could anyone of you please help me on this?
    Thanks in advance.

    Closing Thread

  • Help! limewire will not work on my Mac mini 10.4.11 now that i cleaned it

    Help! LimeWire will not work on my Mac mini 10.4.11 now that i cleaned it out and had to get the new LimeWire. It keeps asking for Java 1.6 but I'm having no luck. :O( LimeWire was the reason I bought a Mac!

    Very weird day in Firefoxland
    First on a Powerbook G4 running 10.4.11 I respond to an invitation to upgrade to Firefox 4 (like a lot of others). Long story short, I wind up losing the browser altogether -- including all bookmarks. Why? Because neither the Firefox homepage (or CNET downloads) makes it clear that 4.0 is for OS 10.5 only! Amazing!
    Then I try to register to post a reply in a thread that crits Firefox for not making this System Requirements info upfront clear. But the Register page I’m taken to (https://support.mozilla.com/bs/users/register) is in SERBO-CROATIAN!!
    Then I try to log into Chat a couple of times and when it’s not CLOSED its a long line waiting and THEN it closes.
    WOW!! Are the wheels off the wagon here or what!?!

  • HT201272 I need a refund on my books I purchased from itunes because my ipod will not support them. I was on the apple chat last night and they tried to help but it did not work and they told me my ipod was to old to support them. I was wondering how do I

    I need a refund on my books I purchased from itunes because my ipod will not support them. I was on the apple chat last night and they tried to help but it did not work and they told me my ipod was to old to support them. I was wondering how do I get the refund on them?

    Try the 'report a problem' page to contact iTunes Support : http://reportaproblem.apple.com
    If the 'report a problem' link doesn't work then you can try contacting iTunes support via this page : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Hi can you help the sound is not working on my Mac I have went into settings and there are no option for interal speaker help

    Hi can you help the sound is not working on my Mac I have went into settings and there are no option for interal speaker help

    Read the documentation at the links.  They won't hurt your data. 
    Basically smc reset is shutdown, pull your plug for 15 seconds, plug it back in, wait 5 seconds, and reboot.  Harmless to you.  Resets the smc.
    Pram reset is similar but you need to push commnd-option-P-R after the boot chime.  Read what does.
    smc and pram reset

  • Plz help me my facetime not working and no have facetime app

    plz help me my facetime not working and no have facetime app

    In what way is it not working?
    Which iPhone do you have?
    Which iOS version?
    Where did you purchase your iPhone?
    Any info at all about your issue?

  • I can buy my needs from the game says I tell customers to help please help me Visa card not working in any Itemes games

    I can buy my needs from the game says I tell customers to help please help me Visa card not working in any Itemes
    games

    If you mean that you have been instructed to contact iTunes support, then will need to do what it says, contact iTunes Support. These are user-to-user support forums, if you thought you were contacting Apple by posting here. Go here:
    http://www.apple.com/emea/support/itunes/contact.html
    to contact the iTunes Store.
    If that does not answer your question, try posting in your native language, or find a friend with a better command of English to help you ask your question here.
    Regards.

  • Urgent help - MUSE email form not working - PLEASE HELP

    HI to all!!
    I'm having a big issue here with Adobe Muse cc 7.0
    I have my personal domain www.shepherdtextiles.com
    and third party host (here in China which is 72e.net (and yes, got all php and so on requirements Adobe Muse needs)
    I follow carefully all steps to add a simple contact form, adding first [email protected] and changing it to my personal hotmail when I saw it wasn't working to try if with hotmail could work, but didn't.
    I have checked the Muse PHP Diagnostics  and as you can see the mail one failed.....
    I used first the simple contact form that comes with Muse and later I used one from museresources.com but none of them seemed to work
    I'm just guessing that something is not well setup on my server because I just follow all steps Adobe mentioned and I watched many videos where people do it very simple.
    The error I get on my website when I click on submit button is "The server encountered an error"
    There is NO error when I export to html or warnings, just exports fine.
    PLEASE HELP
    Many many thanks!
    Vic

    I'M having a similar problem with my Muse website Formally hosted by GoDaddy. The contact me widget does not send an email when you click submit button. Normally, it accepts with a green check mark in another screen. It does not do that. The submit just turns black when clicked, but nothing else happens
    THe he regular email works. I am able to send and receive. It just does not work with the contact widget

  • My mic is not working please help, my mic is not working please help

    my mic is broken i think at first i thaught it was cloged so i put a pin in it but it still would not work . i did get water on my ipod 5 but i dont understand why it only affected my mic intead of anything else please help me anyone

    Try:
    - Reset the iOS device. Nothing will be lost       
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                                
    iOS: How to back up                                                                                     
    - Restore to factory settings/new iOS device.             
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem. Ither the water damaged the mic or the pin did.
      Apple Retail Store - Genius Bar                              

  • Help for date field not working after upgrade

    hi experts,
    In our BSP application for a page we had an inputfield (date).
    Onvaluehelp for input field we were calling the saphelpdate function.
    however after upgrade this functionality is not working properly as no pop up comes after clicking on the icon.
    we have upgraded to SPS 16 recently.
    please help me.
    regards,
    Arvind.

    Hi, I try upper case but nothing happen. This is all my code by far, I hope you can help me:
    DATA: BEGIN OF T_PCONT OCCURS 0,
          PCONT LIKE ZPSPERMISOS-PSOBKEY,
    END OF T_PCONT.
    DATA: BEGIN OF T_FIELDS OCCURS 0.
            INCLUDE STRUCTURE help_value.
    DATA END OF T_FIELDS.
    DATA: BEGIN OF T_VALUES OCCURS 0,
          VALUE(60) TYPE c.
    DATA: END OF T_VALUES.
    DATA: N TYPE i.
    SELECTION-SCREEN BEGIN OF BLOCK  b20 WITH FRAME TITLE text-b02.
      SELECT-OPTIONS:
        P_CONT FOR  ZPSPERMISOSH-PSOBKEY OBLIGATORY NO-EXTENSION NO INTERVALS,
        P_INT  FOR  ZPSPERMISOSH-PARTNER OBLIGATORY NO-EXTENSION NO INTERVALS,
        P_FEC  FOR  ZPSPERMISOSH-ZFINICN NO-EXTENSION NO INTERVALS,    
        P_RAZ  FOR  ZPSPERMISOSH-ZRAZONFINIC NO-EXTENSION NO INTERVALS.
    SELECTION-SCREEN END OF BLOCK b20.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_CONT-LOW.
      PERFORM P_HELP_P_CONT USING P_CONT-LOW.
    *&      Form  P_HELP_P_CONT
    FORM P_HELP_P_CONT  USING P_P_CONT.
      DESCRIBE TABLE T_PCONT LINES N.
      IF N EQ 0.
        T_FIELDS-FIELDNAME  = 'PSOBKEY'.
        T_FIELDS-TABNAME    = 'ZPSPERMISOS'.
        T_FIELDS-SELECTFLAG = 'X'.
        APPEND T_FIELDS.
        CLEAR T_FIELDS.
        SELECT PSOBKEY FROM ZPSPERMISOS
        INTO  TABLE T_PCONT.
        SORT T_PCONT BY PCONT.
      CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE'
        EXPORTING
          CUCOL        = 10
          CUROW        = 1
          TABNAME      = 'T_PCONT'
          FIELDNAME    = 'PCONT'
        IMPORTING
          SELECT_VALUE = P_P_CONT
        TABLES
          FIELDS       = T_FIELDS
          VALUETAB     = T_VALUES.
    ENDFORM.                    " P_HELP_P_CONT
    Edited by: J. Garibaldi on Nov 25, 2009 11:14 AM
    Edited by: J. Garibaldi on Nov 25, 2009 11:16 AM

  • Search help of material is not working in ECC 6.0 : Urgent

    Hi Friends,
    I am using ECC 6.0. I have a problem in search help of material by plant. In the search help of material (choosing the tab plant material by descriptions), if i give any plant which is 3 chars long (exp. ABC) it is giving correct combination of plant material. But if i am giving a plant which is 4 chars long (exp ABCD) it firing a message saying no values found, although the combination exist. (if i am giving only material name it is showing both 3 chars and 4 chars long plant).
    for ref: please use transaction MD04 and press f4 in material field and choose tab "plant material by descriptions", and give 3 chars and 4 chars long plant.
    please help me to trace the problem or any OSS note.
    correct answer will be awarded.
    I will appreciate to not giving code of search helps because it is a standard SAP functionality that is not working.
    Regards
    Krishnendu

    Krishnendu,
    Please check your SAPGui frontend i think you are using 7.10 patch level 3.? if not try with some other system that have 7.10 patch level 3.

  • Help! Keyboard suddenly not working

    im back from school trip and when i turn on my computer, suddenly part of my macbook pro's keyboard isnt working...
    the not working keys: 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, +/=
    Q, W, E, R, T, Y, U, I, O
    I need to use my laptop at school and its not possible for me to carry an external keyboard around, plz help!
    Note: things started to get weird after I open Far Cry 2, i dunno if its related, but after i open it, the number keys stopped working too. Also I am using windows, but its the same problem on mac as I already checked

    Last =night =mine =started =acting =up =too. =as =you =can =see =the =space =bar =gives =me =an =equal =sign. =The =delete =key =works =but =also =turns =up =the =volume. =various =other =keys =seem =to =be =linked.

  • Multiple JVMs within app server - refresh of metdata not working

    Hi guys.
    We have an interesting scenario at present when running our application within a new test environment.
    Our web-based application has the facility to refresh it's application metadata. This should mean that the next time the browser refreshes (or a user logs in to the application), the application will display based upon the refreshed metadata structure.
    Previously, we have run our application on an app server with a single JVM without any dramas. ie. the refresh has always been reflected appropriately when viewing the application - as mentioned above.
    However, we have installed the application in a new environment where the refreshing of meta data does not work consistently. That is, only about 50% of the time does the data refresh correctly. This can be seen by pressing the refresh button in an IE browser, so that the refreshed data appears approx. every second time the button is pressed. The only notable difference with this environment is that it runs 2 JVMs within the app server.
    It seems that in this case, the 'old' data remains cached for the 'other' JVM, and that when the browser receives 'refreshed' data from the server, it does not always source from the same JVM.
    This situation can be resolved by restarting the OC4J container, but this is not a desireable solution.
    Is anyone aware of an OC4J parameter that can be set so that the 2 JVMs can run in synch so that both are refreshed appropriately when our meta data is cleared (refreshed) ? I don't believe this can be controlled within the Java source code, but I'm receptive to any other alternate solutions.
    Thanks in advance.
    Steve.

    I'd like to embed multiple instances of the JVM within
    a single, multi-threaded native server process. I'm
    aware this was not possible with the Sun JDK in the
    past.
    Is this still true (for JDK 1.4.1 say)?Yes, this is still true.
    If it's still not possible, are there any timetables
    as of when it might be available? No.
    Likelihood?Check the current list of JSRs at http://www.jcp.org.
    Ah, btw: Is support for VM unloading (during
    DestroyJavaVM()) available now?No.
    >
    In any case: does anybody know of a JVM
    implementation
    available for Linux which supports multiple VM
    instances within a single process?Why do you need multiple VMs? Would multiple separate 'processes' within a single VM work? If so, have a look at:
    http://www.cs.utah.edu/flux/janos/janosvm.html
    http://www.javagroup.org/echidna/
    Jim S.

  • Refresh all worksheet not working in smartview 11.1.2.2.300

    Hi All,
    We have a excelsheet report which contain multiple sheets in it. These all sheets have essbase report using HsGetValue formulas. Now when we are clicking on 'Refresh all worksheet' its not working however single sheet refresh works. Can you anyone please sugget what will be the issue?
    Thanks,

    Hi,
    I didn't understand your first question. Can you please explain it more?
    In smartview log I'm getting below error-
    [2015-02-17T19:07:32][SVC][ERROR:1][SVC10000][SVC][ecid: be2ca10d-c2a6-4146-b8d0-21ec0852f46a,0]Registry write operation failed (System.NullReferenceException): Object reference not set to an instance of an object.
       at B8CEB14D_B26A_48bf_80BC_18D4B75F6D5F.ExtensionUpdater.GetBoolSetting(String strName)
    Thanks,

  • Please Help. Ipod Screen Not Working

    My screen on my ipod does not work any more.
    I have tried restoring/updating it.....everything!!
    problem is this is my second due to a faulty battery on the first which apple exchanged free of charge for me so I ma not sure if I am entitled to another ipod or what!!!
    If anyone knows how to get the screen working or about 2nd exchanges then please help,
    Thanks,
    Louise x

    If you truly have tried resetting/restoring, then it's time for service. Is it still under warranty, because if so, it won't matter that you have had one exchange already?

Maybe you are looking for

  • How do I resolve a confict between Acrobat X Pro and Microsoft Office 2010 running on a W7 Pro 32bit

    After I use Acrobat X Pro, and particularly if I have Acrobat X Pro running, the Microsoft Office 2010 programs (Outlook, Excel and Word) become very unstable. Outlook has a real tendency to crash when I try to add a file attachment to an email. Word

  • Different types of support

    can anybody given idea about whats the difference between PRODUCTION SUPPORT AND DEVELOPMENT SUPPORT. Also difference between tickets posed by customers  and developers or programmers. Can anybody send some docs abt support to my email id: [email pro

  • Report Designer Urgent

    Hi all,           We have a BI 7.0 system, and Iam able to insert a data provider (query) in my Report Designer and able to change the report as per requirement and save it too. The problem is once i have made the necessary changes, i want to view th

  • Blue Streaks Running Down Screen! Help? Image Enclosed.

    Well, that is weirder still!  The images do NOT show up on a Screen Grab but are visible on every page and picture. Does anyone know what might have happened here?  I noticed a small bluish mess in my upper right hand corner and it has now become mul

  • Having Issues With Java for installation

    Hi Guys, I've played Football manager on my my ibook g4 for years, i installed the latest one last september and it was running perfectly, however i decided to uninstall it during a busy study period to aviod distractions, however when i went to rein