How can I update components position after a setSize call?

Hi there. I need some help. I have a JFrame application. When you press a button, the JFrame size changes, but the components added to it keep in the same position, they dont update to the new size, until I change manually the size of the JFrame, with the mouse. How can I make they to update automatically when I call the setSize(20,40) ?
Thank you!
The code:
public void actionPerformed( ActionEvent event )
setSize(300,90);
repaint();
}

Thank you Encephalopathic for your answer. I try calling revalidate() but it still doesnt work. The SSCCE is here:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Panel extends JFrame implements ActionListener {
     private JPanel panel1;
     private JPanel panel2;
     private JButton btn1;
     private JButton btn2;
        private Container container;
     public Panel(){
             super( "Title" );
            btn1 = new JButton( "Resize");
            btn2 = new JButton( "btn2");
            btn1.addActionListener(this);
            panel1 = new JPanel();
            panel2 = new JPanel();
                  panel1.add(btn1);
            panel2.add(btn2);
                  container = getContentPane();
            container.add(panel1);
            setSize(315,325);
                  setVisible(true);
     public void actionPerformed( ActionEvent event ){
               setSize(100,100);
                  container.remove(panel1);
               container.add(panel2);
                  panel2.revalidate();   // doesnt work
            container.validate(); // doesnt work
     public static void main (String args[]){
               Panel panel = new Panel();
}Edited by: gasbor on Feb 28, 2009 10:09 PM

Similar Messages

  • How can I update the children after updating a node in a tree?

    Hi everyone.
    I'm trying to update a subtree programatically while using a managed bean as data source.
    All topics I can find are about using VOs and JUCtrlHierNodeBinding.updateValuesFromRows.
    Now I need to find some way to directly update nodes without any Row. What should I do?
    Here's the code:
    tags:
                                    <af:tree id="tframe" initiallyExpanded="true"
                                             selectionListener="#{backingBeanScope.systemDataFrameBB.onSelectNode}" var="n"
                                             binding="#{backingBeanScope.systemDataFrameBB.tframe}"
                                             value="#{systemDataFrameMB.treeData}" expandAllEnabled="true"
                                             rowSelection="single" fetchSize="-1" contentDelivery="immediate"
                                             immediate="true" summary="summary">
                                        <f:facet name="nodeStamp">
                                                      <af:group>
                                                      <af:outputText value="#{n.is_system?'[SYSTEM]':''}" />
                                                      <af:outputText value="#{n.is_use?'':'[X]'}" />
                                                                     <af:outputText value="#{n.data_frame_name}"/>
                                                      </af:group>
                                        </f:facet>
                                    </af:tree>
    managed bean(systemDataFrameMB):
         private ChildPropertyTreeModel treeData;
         public ChildPropertyTreeModel getTreeData() throws SQLException
              if (this.treeData == null)
                   AuthAMImpl authAM = this.getAppModule();
                   List<DataFrameNode> subTrees = authAM.getDataFrameTrees();    // load with JDBC and POJO
                   DataFrameNode root = new DataFrameNode();      // insert all sub-trees into a new tree
                   root.setData_frame_id(0);
                   root.setData_frame_name("[ROOT]");
                   root.setParent_data_frame_id(Integer.MIN_VALUE);
                   root.setIs_system(true);
                   root.setIs_use(true);
                   if (subTrees != null && subTrees.size() > 0)
                        root.setChildren(subTrees);
                        for (DataFrameNode n : subTrees)
                             n.setParent(root);
                   this.treeData = new ChildPropertyTreeModel(root, "children");      // I guess this is the simplest way to show hierachical data...
              return this.treeData;
    model:
    public class DataFrameNode
         private int data_frame_id;
         private String data_frame_name;
         private int parent_data_frame_id;
         private boolean is_use;
         private boolean is_system;
         private DataFrameNode parent;
         private List<DataFrameNode> children;
            // getters/setters are omitted....
    backing bean(systemDataFrameBB):
            // edit event handler
         public void onEditResult(DialogEvent de)
              String name = (String)this.getItName().getValue();
              boolean isUse = this.getSbcIsUse().isSelected();
              SystemDataFrameMB dfMB = (SystemDataFrameMB)JSFUtils.resolveExpression("#{systemDataFrameMB}");
              try
                   node.setData_frame_name(name);
                   node.setIs_use(isUse);
                   dfMB.updateNode(node);                   // persist changes, this method will change all the children's 'is_use' field to FALSE when isUse == FALSE
                   AdfFacesContext.getCurrentInstance().addPartialTarget(this.getTframe());      // refresh the tree, only the edited node will be updated, but I want the tree to update the whole sub-tree to reflect the change on all its children
              catch (Exception e)
                            // omitted...
            }

    I solved the problem using RichTree.visitChildren :)
    Maybe not the proper way, but at least it works...
                                    <af:tree id="tframe" initiallyExpanded="true"
                                             selectionListener="#{backingBeanScope.systemDataFrameBB.onSelectNode}" var="n"
                                             binding="#{backingBeanScope.systemDataFrameBB.tframe}"
                                             value="#{systemDataFrameMB.treeData}" expandAllEnabled="true" rendered="true"
                                             rowSelection="single" fetchSize="-1" contentDelivery="immediate"
                                             immediate="true" clientComponent="true" summary="summary">
                                        <f:facet name="nodeStamp">
                                            <af:panelGroupLayout id="tg">
                                                <af:clientAttribute name="node_path" value="#{n.node_path}"/>
                                                <af:outputText id="tIsSystem" value="#{n.is_system?'[SYSTEM]':''}"/>
                                                <af:outputText id="tIsUse" value="#{n.is_use?'':'[X]'}"/>
                                                <af:outputText value="(#{n.data_frame_id})#{n.data_frame_name}"/>
                                            </af:panelGroupLayout>
                                        </f:facet>
                                    </af:tree>
    private static final String PARENT_NODE_PATH = "PARENT_NODE_PATH";
    // all nodes should have a 'node_path' property whose value looks like 'id1/id2/id3'
    // keep path on view root
    FacesContext.getCurrentInstance().getViewRoot().getAttributes().put(PARENT_NODE_PATH, node.getNode_path());
    // visit the whole tree to find specified nodes
    VisitContext vc = VisitContext.createVisitContext(FacesContext.getCurrentInstance());
    RichTree.visitChildren(vc, this.getTframe(), new VisitCallback()
              @Override
              public VisitResult visit(VisitContext visitContext, UIComponent uIComponent)
                   if (uIComponent instanceof RichPanelGroupLayout &&
                        visitContext.getFacesContext().getCurrentPhaseId().equals(PhaseId.INVOKE_APPLICATION))
                        String parentPath = (String)visitContext.getFacesContext().getViewRoot().getAttributes().get(PARENT_NODE_PATH);
                        if (parentPath != null & parentPath.length() > 0)
                             // if current node is in the sub-tree then update its state
                             String path = (String)uIComponent.getAttributes().get("node_path");
                             if (path != null && path.length() > parentPath.length() && path.charAt(parentPath.length()) == '/')
                                  RichOutputText t = (RichOutputText)uIComponent.findComponent("tIsUse");
                                  JSFUtils.refreshTarget(t);
                   return VisitResult.ACCEPT;
         });there might be another solution which uses JavaScript:
    I found out that the HTML tag ADF generated has a attribute like "id='0_1_2_3'", that means I can find the sub-tree with JavaScript.
    But it was not tested 'cause I don't think it would be stable.
    it looks like this:
    StringBuffer clientId = new StringBuffer(node.getLevel_id() * 4);
    while (node != null)
         clientId.insert(0, node.getData_frame_id());
         clientId.insert(0, '_');
         node = node.getParent();
    JSFUtils.executeScript("disableSubTree('" + (clientId.length() > 0 ? clientId.substring(1) : clientId.toString()) +"')");
                <af:resource type="javascript">
                  function disableSubTree(id)
                      // find the adfrichtree component and traverse it, trying to find the sub-tree and modify the nodes
                </af:resource>

  • How can i recover my voicemails after updating my iPhone?

    How can i recover my voicemails after updating my iPhone?

    When one restores an iPhone from its own backup, visual voicemail is also restored. However, when one restores a new iPhone from a backup from a previous phone, the voicemails fail to restore. This occurred between my 3G to 4s, and again from the 4s to a 5s. Restoring the 4s once from its own backup resulted in voicemail recovery.
    My only explanation is that when a different SIM card is used, voicemails cannot restore as one would otherwise expect. Perhaps voicemails are inexplicably tied to their SIMs. Unfortunately, newer models of iPhones tend to use exceedingly different sizes, rendering one possible fix unpursuable. iBackupBot is the other possible solution: you can extract the voicemails from the backup and restore them onto the new iPhone individually.

  • HT4623 My sister has given me an old iPod touch 2 I think it is and after resetting the account info to mine the content was wiped and can not load any games now as it runs 3.1.3 and there all saying they need iOS 5 how can I update it to this

    My sister has given me an old iPod touch 2 I think it is and after resetting the account info to mine the content was wiped and can not load any games now as it runs 3.1.3 and there all saying they need iOS 5 how can I update it to this

    I suspect you have the original, 1G iPod touch. Those can only go as high as iOS 3.1.3,
    If y ohave a 2G those can go as high as 4.2.1
    Identifying iPod models
    To update
    The Settings>General>Software Update comes with iOS 5 and later.
    Connect the iPod to your computer and update via iTunes as far as your iPod model allows
    iOS: How to update your iPhone, iPad, or iPod touch
    A 2G to 4.2.1. Requires iTunes version 10.X. If a Mac it requires OSX 10.5.8 or later.
    To more easily find compatible apps:
    iOSSearch - search the iTunes store for compatible apps.
    Vintapps 3.1.3 - paid app.
    Apple Club - filter apps by iOS version.

  • How can I access apple store after updated to OS- 6?

    How Can I access apple store after updating my i pad to OS-6?

    Look here:
    C:\Program Files\National Instruments\LabVIEW x.x\examples\imaq\*.*

  • I updated my iphone to ios 7.1.1 and after that my contact photo when i call or call others to me is a small cycle of that picture i choose ... How can i make a big picture when i call my contant and when others call me ?

    I updated my iphone to ios 7.1.1 and after that my contact photo when i call or call others to me is a small cycle of that picture i choose ... How can i make a big picture when i call my contant and when others call me ?

    It's not clear why Apple made this change; speculation (which is not really allowed in these forums) is that it was done to protect the privacy of the caller.

  • After installing yosemite, tried to update apps but an old apple id is shown with no way to edit. how can i update apps wait my current app;e id and password?

    after installing yosemite, tried to update apps but an old apple id is shown with no way to edit. how can i update apps wait my current app;e id and password?

    You need to delete and redownload them to do that. This may require repurchasing paid ones.
    (116535)

  • How can I update my iPhone 3gs to iOS4, after iOS5 came out?

    I am still running iOS 3 (1.3) on my iPhone 3GS and I'm happy with it - but all the new apps requires iOS4 and now I'm sick of this. I want iOS4 (and not iOS5, cause it will drain my battery as far as I've understood).
    How can I update my iPhone 3GS in a normal way to iOS4, through iTunes or another easy way? I have never jailbreaked an iPhone so I don't know too much about "backdoors" into my iPhone.

    The only Firmware in the iOS 4 series that Apple is still signing for the iPhone 3GS is 4.1. So you could restore  to 4.1. You will have to download the 4.1 IPSW from Apple, and then install it with iTunes, Option Click Mac or Shift Click Windoz, on the Restore Button and then select the 4.1 IPSW on your computer. The current iTunes may give meaningless Errors, I doubt because you are Upgrading. But if Error Message is given you will have to search the Web for ways to Exit Recovery.

  • I have an iMac mid 2009 with snow leopard.  I was so excited awaiting Lion, however, I am now afraid to download after hearing all about all the problems.  Should I wait awhile or go for it? my printer is showing power pc. How can I update printer to univ

    I have an iMac mid yr 2009 with snow leopard.  I checked and my howdoi.swf 8.o r22 is power pc and my HP sofware updater is also power pc.  How can I update these appls to be compat with Lion, as I am not computer savvy.  or should I wait awhile to install Lion?

    Lion upgrade questions and answers:  Apple Support Communities
    You may want to hold off upgrading to Lion for a bit and check with the HP site to see if they will update their HP software for Lion compatbility.

  • How can i update my xperia ray into ICS?

    i have tried the update with pc companion but it is showing an error "Unable to install or start phone software update components". I have also downloaded the SUS software but it is not working in my windows 8 machine. Is there any way to upgrade the OS directly from mobile? Or how can i update it in any other way?
    Solved!
    Go to Solution.

    We don't have a PC companion version tested for Windows 8. (Microsoft® Windows XP™ SP2 (32 bit), Vista (32/64 bit) or Windows 7 (32/64 bit) Only) That's the issue in your case.
    But try this:
    If you are getting the error "unable to install update components"
    1. Close Pc companion
    2. Install Java from: http://www.java.com
    3. start Pc companion again and try to do the software unlock process once more.
    Then:
    Run the Pc companion Software
    Turn the phone off and disconnect it from the computer
    1. No matter what the program says do not connect the phone until you complete step 9
    2. In the welcome screen if asked click on start, Next you will be shown what media go offers, click on "next" then you will see a presentation on what support zone offers, click on "Finish"
    3. In the next section from "support zone" and "media go" new select "support zone"  and click on start.
    4. On the next page select "Software update" and click on "start"
    5. The program will say that there is no phone connected and will ask you to connect but disregard that and instead choose the option to "repair Phone".(the program will issue you a warning on the content that you will lose during the update)
    6. Choose the option to continue.
    7. After that, the program will download the necessary information (5 to 6 minutes) and it will present you with a list of phones.
    8. Choose the Phone from the list (close to the bottom of the list)  click on the icon for the phone and then click on "next"
    then you will see a new section telling you how to connect the phone. (don't connect it yet)
    At this point the phone must be off and disconnected from the PC.
    9. Connect the cable to the PC not to the phone, then follow the instructions on screen to connect the phone, if done correctly the program will say "the update of your phone has started..." (in some cases a message of  "Installing drivers" will appear before the message of "the update of your phone has started..."  is shown.)
    10. If you failed to follow the steps correctly the phone will turn on and it will request that you "Proceed with the following steps, slide down the notification bar", If this happens disconnect the phone from the cable, turn it off and repeat from step 9).
    11. If the PC Companion proceeds correctly wait for the update to finish and follow instructions on screen.
    Hope this helps.
    Francis

  • How Can I Update the coils on Quantum PLC...

    Dear Sir,
    I am in the process of configuring Lookout4.5 build9 with Quantum PLC.
    I am trying to write two O/p coils of the PLC using two latchgate
    objects. I am using two different set of push buttons for latching
    and unlatching the two latchgates. After this I have directly
    connected the two latchgates to the O/P coils of Modbus object
    in modbus ethernet mode of communication.
    Now I am using the PLC simulator s/w of PLC to watch the status.
    When I start the first pump (coil1) and Stop the second(coil2),
    after sometime it is seen that the position is reversed such
    that the coil1 is off and coil2 is On. Though here in Lookout
    I see that the latchgate 1 is ON and latchgate2 is OFF.
    I am
    unable to understand this change over in the status of the coil.
    I have read one of the documents on NI website (Document ID:15QA2P9C
    "Why can't I update the coils on Quantum PLC without reading them
    back in?" Report dated:01/27/98). I think my problem is similar
    to that.
    So please tell me a proper method of updating the coils on Quantum
    PLC or how can I update the coils by reading them back ?
    OR is there any problem regarding the modbus.cbx file, if so please
    send me the latest modbus.cbx for Lookout4.5
    Waiting for your earliest response...
    Yours Truly,
    Girish Nalgirkar
    Theta Controls
    Pune, India.

    The KnowledgeBase that you refered to is 3-1/2 years old, and the problem in the modbus driver is long-since fixed. Their are no other known issues with the Modbus driver.
    The method you are using to update the coil sounds appropriate. What I would first verify is that Lookout is not sending a command to toggle the coil.
    1) Write the simplest possible process that shows the problem (ie 2 pushbuttons, the modbus object, 1 latchgate).
    2) Create a "modbus.ini" file in your Lookout directory. Place the following in the modbus.ini file:
    [ethernet]
    DiagnosticPath=c:\
    3) Run your program until the problem occurs. If it does, find the "modbus1" file created in the C:\ directory. This file contains a log of all modbus communication that moved back and forth. Check the
    log to see if Lookout sent a command to the PLC. If no command was sent, then the change occurred internal to the PLC software.
    Regards,
    Greg Caesar
    National Instruments,
    Applications Engineer

  • How can i update data in JTable at run time ?

    i am trying to build a client/server architecture for conducting quizzes & online tests.. My client will return a object to the server after the test is over, which contains details about the participant, his score and other details. i am putting the incoming object to an Vector. I'll create a new thread each time for the incoming connection and insert the object to the Vector.. Now, please tell me tat, how can i update my table automatically at run time so tat, my table is updated whenever a new object is entered into vector..
    here is my code for the table..
    public class MyTableModel extends AbstractTableModel {
        String columNames[] = { "ID", "NAME", "COLLEGE", "SCORE", "CELL" };
        /** Creates a new instance of MyTableModel */
        public MyTableModel() {
            Main.List = new Vector();
            SetDefaultData();
        public int getRowCount() {
            return Main.List == null ? 0 : Main.List.size();
        public int getColumnCount() {
            return columNames.length;
        public String getColumnName(int column) {
            return columNames[column];
        public boolean isCellEditable(int row,int col) {
            return false;
        public Object getValueAt(int rowindex, int columnindex) {
            if(rowindex < 0 || rowindex >= getRowCount())
                return "";
            Student row = (Student)Main.List.elementAt(rowindex);
            switch (columnindex)
                case 0 : return row.id;
                case 1 : return row.name;
                case 2 : return row.college;
                case 3 : return row.score;
                case 4 : return row.cell;
            return "";
        public String getTitle() {
            return "Student Table";
        private void SetDefaultData() {
            Main.List.removeAllElements();
            Main.List.addElement(new Student("CS041","Keerthivasan M","MNM",95,"9884326321"));
            Main.List.addElement(new Student("CS012","Arun M","MNM",90,"9884825780"));
            Main.List.addElement(new Student("CS019","Balaji S","MNM",79,"9841742068"));
            Main.List.addElement(new Student("CS005","Anand R","MNM",89,"9884130727"));
            Main.List.addElement(new Student("CS045","Manish J","MNM",55,"9841624625"));
            Main.List.addElement(new Student("CS013","Mangal S","MNM",5,"9841961742"));
    }

    In the future Swing related questions should be posted in the Swing forum.
    how can i update my table automatically at run time so tat, my table is
    updated whenever a new object is entered into vector..You don't update the Vector directly. You should be creating a method in your TableModel, called "addRow(...)". This method will do two things:
    a) add the Student object to the Vector
    b) invoke the fireTableRowsInserted(..) method of AbstractTableModel. This will cause the table to be repainted.

  • I can't update my apps after upgrade to iOS 6...?

    I can't update my apps after upgrade to iOS 6

    Are you sure you have a proper Internet connection? Make sure your iPod is connected to your computer, and you have an Internet connection.
    Don't even get me started on the iPod Touch 5G, I actually own an iPod Touch 4G, and I've considered a lot about if I should get the new one. At first look, you might be sold by the features Apple has on their iPod Touch page. It has a taller screen that's a 4-inch Retina Display, has a much better camera with a flash, and comes with iOS 6 preinstalled with Siri. But the real breakthrough comes with the new connector. It's called Lighting, and it's much smaller. But if you have a dock connector that comes with some cars, and maybe a set of speakers or docking stations as alarm clocks, I encourage you not to get the new one. The usage of your old connectors requires a $30 adapter, which is a ridiculous price. And who knows how secure the adapters will be with your docking stations? I personally think Apple has crossed the line. If they are to put a new connector with their new products, they should ship with an adapter in the box, at least at first. This is why I strongly encourage you NOT to get the new 5th generation iPod Touch.
    Sorry if I went a little off-topic there, but I wanted to get my point across. For your updating to iOS 6, I reccommend you check out other discussions in the support comunity, and see what other contributors have to say. Or go on Google and search your error messages, possibly someone might've already went through the same problem as you did. I really hope this helped!

  • How Can I update my app new version to the registered devices

    Well, we have developed an in-house app using the Unity3d Game Engine. I'm using a Developer Enterprise account, and have already created the proper certificates, registered the devices (7 ipads) and generated the provisioning Profile. I have already clicked in the 'build an run', and the Unity Engine builds the app, that after is opened at the Xcode. I havel already fixed the bugs, and the app is working properly at the ipads.
    The problem is, I will need to Update the app, and I need to Update them without have to get them and build them at my own Mac, since they do not stay with me. I've been strugling with that for a while. I have downloaded the provisioning profile and sent by e-mail to one of the ipads, the one I'm using to test, and instaled it, but the version of my app have not been updated.
    I checked on my app icloud capabilities. The page about the Update of in-house apps is not very clear(http://help.apple.com/iosdeployment-apps/mac/1.1/#app43ad802c), and I'm new in the development for IOS.
    How can update my app at this Ipads? Is there any step-by-step to follow, more eplanatory that the link above?

    I didn't explained it correctly, I mean without getting the ipads, not the source code. I mean, at every time I need to launch a new version of the app, how can I update it through the internet, because I have installed my app running it at the ipads with the xcode, by usb. I'm using the enterprise program, so, as far as I know, the update is not through apple store.
    The ipads are in use, and I'd like to update them without have to get them to install it myself. Hope I have explained it better this time. Thank you for your help.

  • How can I update my iPod on a new laptop?

    So, iOS 5 is finally out next week.
    I would like to upgrade to it, however since my old laptop is broke I use my mums laptop for iTunes. How can I update my system without apps beinf rid of? Last time I did it, my apps remaines intact, but I don't know how I did this.
    Any help?

    I have shared this thread with a number of users who have reported success with these steps.
    https://discussions.apple.com/thread/3305461
    This was posted for an iPad but it works the same way for an iPod. Important - and this has been covered - turn off auto sync in iTunes first, transfer your purchases next, back up your iPod after that.
    It is all covered in this thread - Demo &amp; King Penguin

Maybe you are looking for