Determining preferred size of a container

Hi,
Does anyone know how to determine the preferred size of a
container that hasn't had it's height/width set?
There are two aspects to this:
1. I would like to resize a container from 0,0 height/width
to it's preferred size.
2. Sometimes the children of the container will be larger
than any arbitrary size that I specify so I need to know when this
occurs so I can expand the size accordingly.
Anyone any ideas how to do this?
I've tried properties:
height/width
explicitHeight/explicitWidth
measuredHeight/measuredWidth
all to no avail. They all return 0,0 even if I don't specify
the initial height/width to 0 and have added it to the parent
container (in this case a WindowedApplication).
Any suggestions would be appreciated :)
Thanks,
Gary

I got around item 1, by using a zoom effect, thus:
var z:Zoom = new Zoom (container);
z.duration = 2000;
z.easingFunction = Bounce.easeOut;
z.zoomWidthFrom = 0.01;
z.zoomHeightFrom = 0.01;
z.zoomHeightTo = 1;
z.zoomWidthTo = 1;
z.play ();

Similar Messages

  • Determine preferred size to be set for the JPanel attached to JScrollBar

    Determine what preferred size to be set for the JPanel attached to JScrollBar.
    Hello all, I am having a JPanel, where new components will be added into it during run-time. When there are too many components inside the JPanel, I need to re-set the JPanel preferred size so that the JScrollBar is scrollable.
    I was wondering what is the good method to determine the preferred size of JPanel during runtime?
    Currently, I am using
    myJPanel.setPreferredSize(new Dimension(
    numberOfNewComponent * preferred width of each component,
    numberOfNewComponent * preferred height of each component
    ));Is there any better alternative?
    Thank you very much.
    yccheok

    Usually a container such as JPanel will calculate its own preferred size from its layout manager - calling setPreferredSize is often unnecessary.
    When you add a component to your JPanel its preferred size will change automatically.
    What's wrong with the behaviour when you simply add your JPanel to a JScrollPane and let it manage its own preferred size?
    Hope this helps.

  • How does JEditorPane determine its preferred size?

    Could someone explain how JEditorPane determines the initial preferred
    size? Its default sizing is not giving me what I need and I'm not sure
    how to control it, other than explicitly setting the size with
    setPreferredSize().
    A simple example:
            String s = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 10 20" +
                       "21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39";
            JEditorPane ed = new JEditorPane("text",s);
            JPanel pan = new JPanel();
            pan.setLayout(new BoxLayout(pan,BoxLayout.Y_AXIS));
            pan.add(ed);
            JFrame f = new JFrame();
            f.getContentPane().add(pan);
            f.pack();
            f.setVisible(true);This code generates a window that shows one line, with "1 2 3 4 5 6 7 8 9"
    showing. I'd like to have a larger area showing initially.
    Does the choice of layout manager effect this? (I actually prefer to use
    TableLayout; the above example with a 1x1 TableLayout and widths set to
    PREFERRED yields exactly the same results.)
    Thanks,
    bw

    Set your ruler increments to pixels Preferences>Units & Increments. You can fill the text box with placeholder text Type>Fill with Placeholder text and get a word count from the Info panel with Show Options turned on from the flyout.
    From the Transform panel you can set a text box's width and height

  • Container preferred size (or size in general)

    If you can get a containers preferred size why can't you set it using
    setPreferredSize(new Dimension(int, int));
    or
    size(int, int)Specific use...
    Container screen; //instance var
    screen=getContentPane(); // init
    I would like to know how to set A containers size given the following
    Have tried many different variations.... This container is in a class in a Java application. (it isn't the main class) It won't auto size itself to a JPanel included inside. (which was added to the Container) (Also plan to add some buttons outside of this panel, but on the container)

    The first error message is telling us that, in the Container api, the method setPreferredSize cannot be resolved, ie, the compiler can't find it. This is when we turn to the api for some research.
    In the Container [url http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Container.html]api, look for setPreferredSize. We scroll down to the Method Summary section and again down to the Methods inherited from the class java.awt.Component section...
    It doesn't appear in either section >> not used/available for the Container class.
    The next two errors are telling us that the size method cannot be used with (int,int) or (dimension) arguments.
    So, in the Component [url http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Component.html]api, scroll down to the Method Summary section and look for size:
    we see that the size() method takes no arguments. Okay, that explains the complaints from the compiler.
    Also, we see that the size() method is deprecated - not to be used anymore. It has been replaced by getSize.
    So let's try the setSize method.

  • Update JScrollBar Extent when JScrollPane Component Changes Preferred Size

    Hi folks,
    I have an interesting, but concise problem that I've been working on for a few days but haven't had any luck.
    In Java 1.5 or Java6, I have a JScrollPane which contains a JPanel. The settings of the scrollbar (for example, the Extent [the width of the "thumb" or "slider" on the scrollbar]) are determined based on the dimension of the underlying contained component, in particular, the Preferred Size.
    My problem is this. The underlying component has a "zoom" capability, such that the actual size of the component can and does change (i.e., zooming out reduces its preferred size).
    Happily, the consequence of this design is that the "size" or extent of the scrollbar sliders/thumbs adjusts to give visual indication of the proportion of the current view (ViewPort View dimension) to the underlying component's dimension.
    The problem is, the scrollbar sliders do NOT automatically update their size in response to programatically changing the JScrollPane's contained component's PreferredSize. They WILL be updated if I RESIZE the parent JFrame manually.
    But for the life of me, I can't get those sliders to update programatically. I've tried repaint(), update, validate(), etc. on the JScrollPane but no luck.
    I've done a debug to get into the stack trace of the Sun code during run time, and there's a lot going on... there's a doLayout(), a reshape() (deprecated), firing various property changes, but I just can't seem to find a good hook into getting the scrollbar to update its internal Bounds model and repaint accordingly. Calling setBounds() on the JScrollPane I think would trigger it, however, looking at the code.. it seems to ignore firing property events and repainting of the bounds themselves didn't actually change (i.e. no action happens if the current dimension and specified dimension in the argument to setBounds() are the same).
    Any ideas here on how to this to get those sliders to update programatically with a new value for the extent?
    Thanks,
    --Mike                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Understood! It was my intention to give credit and now I'm happy to do so! I've now assigned the Duke Points. Minor usability issue, it was not obvious how to do this the first time (and I did poke around a little before I gave up earlier in the day, reverting to just assigning him the correct question). I've got it now though! Thanks again--definitely knocked out an issue I was having today and allowed me to move on to add'l development work today.
    All the best!
    --Mike                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Can I Make Font SIze Respond to Container Resize?

    I have a JDialog.
    I added a JPanel as the content pane.
    I use a GridBagLayout for all JPanels.
    The content pane also has a ComponentListener, and I use its componentResize () method to sense when user drags the Dialog to a new size.
    There are two sub JPanels, and one of them uses a CardLayout to conrol a set of other JPanels.
    All the JPanels have a collection of JTextFields and JComboBoxes that is determined at run time.
    My goal is to permit resizing to any size and keeping all components visible and fonts readable.
    That means controlling the font size.
    Getting a ratio from the requested size change and applying it to change the font size of all components almost works. Its good for all increases up to full screen. However I lose it on the way down. The panels shrink more than the font shrinks the fields and boxes.
    The Title and other insets prevent it from being perfect. There is also some slippage from JComboBox having an independent JTextField editor component. Their heights often are inconsistent, i.e. the JComboBox height ends less than the preferred size of its editor component.
    And, if not careful the componentResize ()degenerates into an infinite loop, i.e. I change the font and then pack () which triggers another call to resize.
    Anyway, does anyone know of a model for this problem.
    My goal is for it to stay consistent no matter how small it is shrunk.
    glb

    Hi Mike,
    That's right, MultiTouch and Gestures can not be used at the same time, but you should always be able to receive mouse events for 1st touch point.
    Could you try changing your code as below.
    function mouseDownHandler(event:MouseEvent):void {
    TweenLite.to(mainMenu.menuPres, .2, {alpha:.5});
    function mouseUpHandler(event:MouseEvent):void {
    TweenLite.to(mainMenu.menuPres, .2, {alpha:1});
    please sprinkle some trace statements in event handler to see if they get triggered.
    Also, did you try just adding event listener for MouseEvent.CLICK, instead of MOUSE_DOWN and MOUSE_UP.
    -Thanks
    Pahup

  • Use of minimum, maximum and preferred size?

    Hi,
    What is the use of the three sizes (maximum size, minimun size and preferred size) of component and container?
    And which class use them?
    Thanks for any ideas and input,
    Wing

    I read somewhere on this forum that most layout managers pretty much ignore these properties... just one of them would properly use it (don't know which one, I think it was one of the 'less-common' ones like Card or BoxLayout).
    If somebody has more info I would wanna read it too!

  • Oracle DBSL -  Determine / Define size of fetch array

    Hello guys,
    i have a question about the Oracle DBSL and how it determines the size of the fetch array.
    I am refering to the following documents / documentations:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/86a0b490-0201-0010-9cba-fd5c804b99a1
    Quote:
    As long as you do not program an UP TO ROWS in ABAP, the database gets as many table rows as possible per communication set (as many as fit in 32k).
    http://help.sap.com/saphelp_nw04/helpdata/en/d1/801f96454211d189710000e8322d00/frameset.htm
    Quote:
    You have to specify the size of an array before runtime. However, because you cannot know the size of the dataset the system will return, you must define a very large array to avoid an overflow.
    To circumvent this problem, the SAP Basis System translates ABAP Open SQL statements into Embedded SQL. To do this, the system defines a cursor.
    Ok but the translated embedded SQL code has also to specifiy an array fetch size (how many rows are retrieved by one fetch).
    Is this a profile parameter or is it really calculated (how many rows of a specified table would fit into 32k) dynamically in the DBSL?
    Regards
    Stefan

    Hello Michael,
    i am refering to the documentation of DEFAULT_SDU_SIZE:
    > Use the parameter DEFAULT_SDU_SIZE to specify the session data unit (SDU) size, in bytes to connections.
    > session data unit (SDU)
    >A buffer that Oracle Net uses to place data before transmitting it across the network. Oracle Net sends the data in the buffer either when requested or when it is full.
    Ok, that controls the transmit moment in the network layer.. but not the number of rows which are returned by a single FETCH call (through the OCI). (For example in sqlplus it can be set with set arraysize XX)
    I have tested also a little bit around with different sap standard tables in an ERP 2005 system.
    I have activated a SQL Trace (ST05) and done a "select * from <TAB>" via SE16 (no count limit!).
    In my tests there were fetched different number of rows -  take a look by your own:
    Time  Object    Operation  Rows   Returncode
    2.451 T100       FETCH     321      0
    1.915 T100       FETCH     321      0
    1.912 T100       FETCH     321   1406
    1.246 E071K      FETCH     109      0
    1.218 E071K      FETCH     109      0
    1.155 E071K      FETCH     109      0
    T100 (4 VARCHAR columns)
    E071K (14 columns of different types)
    So it seems like the DBSL dynamically calculates the number of rows which can be returned by a single fetch call based on the row size (number of columns and column sizes) and other unknown factors.
    If this is true, it would be really great and nothing have to be done by us (the customers!).
    But if the DBSL dynamically calculates the max. number of rows per fetch:
    Why is a "SELECT * FROM <TAB> INTO <ITAB>" preferred - the SELECT Statement in a LOOP (like in the example) is also fetching the max number of rows by each fetch, or?
    The example: http://sap.mis.cmich.edu/sap-abap/abap04/sld017.htm
    That was only a notice on some small tests, which i have done.. maybe someone knows it in detail.
    Regards
    Stefan

  • JTextField border part of preferred size?

    In an attempt to set the height of a JPanel just tall enough to accommodate its tallest component, a JTextField, I accounted for the preferred height of the JTextField and the insets of the JPanel. However, this failed to provide sufficient height to see (at least) the bottom of the JTextField border.
    I had ignored the height of that border (i.e. the border insets), believing that its height would have been included in the preferred height of the JTextField. Was I wrong?
    JTextField.getPreferredSize()
    Returns the preferred size Dimensions needed for this TextField.
    JComponent.getBorder()
    Returns the border of this component or null if no border is currently set.
    In the Swing component set, borders supercede Insets as the mechanism for creating a (decorated or plain) area around the edge of a component.
    Border.getBorderInsets(Component c)
    Returns the insets of the border.
    Alan Feldstein
    Cosmic Horizon
    http://www.alanfeldstein.com/

    Alan_Feldstein wrote:
    4gui wrote:
    Which layout do you use?
    you must use the layout to locate the componet on the place you want.The JTextFields's container ... has a flow layout.4gui got me thinking about what I should have been thinking about after all. In fact, method FlowLayout.getVgap gives the "vertical gap ... between the components and the borders of the Container." I needed to compensate for that too.
    >
    When I inquire about the JTextField's preferred size, will the numbers include the JTextField's border or not?I think so. It has always made more sense to me to consider the borders to be part of a Component. Now I have seen more evidence in the documentation to support this.
    For example, method FlowLayout.getVgap "gets the vertical gap ... between the components and the borders *of the* Container." Those borders belong to the Container, not to anything outside the Container.
    Method JComponent.getInsets says, "If a border has been set on this component, returns the border's insets ...". My Container is a JComponent and I said before that I had already compensated for its Insets (i.e. the size of its border).
    Since the Container's border is part of the Container, for consistency the JTextField's border would be part of the JTextField.
    I had been looking for a way to explain a discrepancy, by considering the theory that the JTextField's preferred size did not include its border, a theory I was never comfortable with. It turns out that the discrepancy came from failure to compensate for the vertical gap in FlowLayout.
    Since 4gui was on the right track, all of the remaining Duke Stars go to him/her.

  • Why is my panel's preferred size changing as I resize the window?

    I have a JEditorPane inside a JPanel, which is wrapped in a JScrollPane. The JEditorPane contains a wide image and I expect to see horizontal scrollbars if the viewport is smaller than the minimum size needed to display the image.
    When my panel is displayed for the first time and the viewport size is smaller than the image, the horizontal scrollbars appear and the size of the scrollable area is set to the width of the image. This is the expected behaviour. When I resize the panel so that its is wider than the image and the scrollbars are no longer needed, the scrollbars disappear. However, when I shrink the panel back, the scrollbars appear at the correct "time" (when the edge of the image is reached), but the scrollable area is too wide, similar to the size I had stretched the panel out to.
    I am printing out the preferred size that the panel is returning (which will be used to set the scrollable area), and it seems to keep changing. The preferred size seems to grow with the panel's actual size, but it does not shrink back when I make the panel smaller.
    Anyone has any idea on what might be happening?

    Welcome to the Sun forums.
    >
    Anyone has any idea on what might be happening?>It probably has to do with the Java code used. Can you prepare an SSCCE that shows the behaviour?

  • FlowLayout  &  preferred size

    ".....FlowLayout always honors the components's preferred size..."
    what is the meaning of this phrase ? what is prefered size ? i know that flowlayout puts components from left to right .( centre allign).
    what does that phrase means ?

    Each component has a method called getPrefferedSize and also one called getMinimumSize which asks the compent what size is wants to be, and what size it needs to be.
    In fact if you want to change the size of a component within a layout the proper way is to create your own subclass of the componet class which overrides these methods.
    The layout manager asks each child component of the container it's laying out for their preffered sizes before deciding how to lay them out and what actual size to set for them.

  • How Can I Determine the Size of the 'My Documents' Folder for every user on a local machine using VBScript?

    Hello,
    I am at my wits end into this. Either I am doing it the wrong way or it is not possible.
    Let me explain. I need a vb script for the following scenario:
    1. The script is to run on multiple Windows 7 machines (32-Bit & 64-Bit alike).
    2. These are shared workstation i.e. different users login to these machines from time to time.
    3. The objective of this script is to traverse through each User Profile folder and get the size of the 'My Documents' folder within each User Profile folder. This information is to be written to a
    .CSV file located at C:\Temp directory on the machine.
    4. This script would be pushed to all workstations from SCCM. It would be configured to execute with
    System Rights
    I tried the script detailed at:
    http://blogs.technet.com/b/heyscriptingguy/archive/2005/03/31/how-can-i-determine-the-size-of-the-my-documents-folder.aspx 
    Const MY_DOCUMENTS = &H5&
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(MY_DOCUMENTS)
    Set objFolderItem = objFolder.Self
    strPath = objFolderItem.Path
    Set objFolder = objFSO.GetFolder(strPath)
    Wscript.Echo objFolder.Size
    The Wscript.Echo objFolder.Size command in the script at the above mentioned link returned the value as
    '0' (zero) for the current logged on user. Although the actual size was like 30 MB or so.
    I then tried the script at:
    http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_27869829.html
    This script returns the correct value but only for the current logged-on user.
    Const blnShowErrors = False
    ' Set up filesystem object for usage
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("WScript.Shell")
    ' Display desired folder sizes
    Wscript.Echo "MyDocuments : " & FormatSize(FindFiles(objFSO.GetFolder(objShell.SpecialFolders("MyDocuments"))))
    ' Recursively tally the size of all files under a folder
    ' Protect against folders or files that are not accessible
    Function FindFiles(objFolder)
    On Error Resume Next
    ' List files
    For Each objFile In objFolder.Files
    On Error Resume Next
    If Err.Number <> 0 Then ShowError "FindFiles:01", objFolder.Path
    On Error Resume Next
    FindFiles = FindFiles + objFile.Size
    If Err.Number <> 0 Then ShowError "FindFiles:02", objFile.Path
    Next
    If Err.Number = 0 Then
    ' Recursively drill down into subfolder
    For Each objSubFolder In objFolder.SubFolders
    On Error Resume Next
    If Err.Number <> 0 Then ShowError "FindFiles:04", objFolder.Path
    FindFiles = FindFiles + FindFiles(objSubFolder)
    If Err.Number <> 0 Then ShowError "FindFiles:05", objSubFolder.Path
    Next
    Else
    ShowError "FindFiles:03", objFolder.Path
    End If
    End Function
    ' Function to format a number into typical size scales
    Function FormatSize(iSize)
    aLabel = Array("bytes", "KB", "MB", "GB", "TB")
    For i = 0 to 4
    If iSize > 1024 Then iSize = iSize / 1024 Else Exit For End If
    Next
    FormatSize = Round(iSize, 2) & " " & aLabel(i)
    End Function
    Sub ShowError(strLocation, strMessage)
    If blnShowErrors Then
    WScript.StdErr.WriteLine "==> ERROR at [" & strLocation & "]"
    WScript.StdErr.WriteLine " Number:[" & Err.Number & "], Source:[" & Err.Source & "], Desc:[" & Err.Description & "]"
    WScript.StdErr.WriteLine " " & strMessage
    Err.Clear
    End If
    End Sub
    The only part pending, is to achieve this for the 'My Documents' folder within each User Profile folder.
    Is this possible?
    Please help.

    Here are a bunch of scripts to get folder size under all circumstances.  Take your pick.
    https://gallery.technet.microsoft.com/scriptcenter/site/search?query=get%20folder%20size&f%5B0%5D.Value=get%20folder%20size&f%5B0%5D.Type=SearchText&ac=2
    ¯\_(ツ)_/¯

  • How to determine the size of an InputStream??

    Hello,
    I need to get the size of an inputstream. In fact, I am working with java.nio.channels and need to tranfer a file from within a Jar to the FileSystem.
    I have created a ReadableByteChannel from the jar resource, and a FileChannel from the FileSystem destination. The problem is that to use the FileChannel .tranferFrom(..) I need the size of the src file. But, ReadableByteChannel has no size() method.
    How can I determine the size of this InputStream??
    advanced Thanx
    here is code:
    private void copyResourcesToFileSystem(){
              try{
                        String name = getFileName(); // gets the name
                        ReadableByteChannel srcChannel =
                             Channels.newChannel(this.getClass().getClassLoader().getResourceAsStream(("dtd/"+name)));
                        File newFile = new File(TempDirCreator.getXmlDir(),name);
                        FileChannel dstChannel = new FileOutputStream(newFile).getChannel();
                        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());  // doesn't work -- there is no ReadableBC.size()
                        // lets close the show
                        srcChannel.close();
                        dstChannel.close();
              }catch(IOException x){x.printStackTrace();}
              catch(Exception ex){ex.printStackTrace();}
         }

    In general the "size of an InputStream" is a meaningless concept. It's possible to have an InputStream that never terminates. So if you can't get a size from whatever you're reading from, you're out of luck.
    I missed where you explained why you need the size. I've never felt the need to know how many bytes would be passing through my code when copying from input to output.

  • How to determine the size (in pixels) of the current mode

    Hello.
    I am looking for a was to determine the size (horizontal and vertical pixels) of the current mode (SAPGUI window). I have already looked through the methods provided by class CL_GUI_CFW...
    CL_GUI_CFW=>GET_METRIC_FACTORS provides the size of you display (i.e. 1600 x 1200 pixels) and some other information I am not able to interprete.
    Futhermore I have had a look at the Methods CL_GUI_CFW=>COMPUTEPIXEL, but I don´t know how to use them.
    Has anybody of you any experiences in this topic? I would be grateful ...
    MIKE

    Sorry Manoj,
    but i didn´t find out, why these programs should be able to solve my issue. They just display a picture using the CL_GUI_PICTURE control.
    I am looking fo a way to resize a given control to the very maximum, so that it fills the whole SAPGUI window!
    Thanks anyway...
    MIKE

  • Determining the size of an Image

    I am running Pages 5.2 and I have a document with a whole load of images taken from photos. Usually I shrink the original images to keep the document size manageable but I forgot on some but I don't know which. Is there a way I can determine the size of individual images in the document ?

    In Pages v5.2, there does not appear any means to assess the image storage size, but File > Reduce File Size will offer a prompt stating an amount it can reduce the current selected image.
    Another approach is to select the image, and press command+C to put it on the clipboard. Launch Preview, ignore the open dialog, and choose File > New from Clipboard. You now have two choices to assess image size: 1) Use the Inspector (General Info panel) from the toolbar, or 2) Menu > Tools > Adjust Size...

Maybe you are looking for

  • How to get result of querry independet of a datatype?

    Hi All! I try to write a program, that calls stored procedures in a database independent of a name and arguments list. To get a result of a query I must call one of the functions getInt(), getString() etc. of CallableStatement. I'd like to write a wr

  • Regarding allignment in classical report, need it urgently

    Iam strucking in dispalying the data in classical report. Iam working with hr module. My output should be in such a way that all the countries which iam taking in one internal table shuld be displayed in row. with regarding these countries I was fetc

  • SQL Function for calculating IP Address

    Hi Experts , I have an IP Range i need to find out the First Host detail for the IP using a SQL scalar function . Example : 11.30.10.40 Subnet Mask is 26 Output required First host: 11.30.10.1 am confused how i can derive the first host  values from

  • Call EP and ERP through web dispatcher

    Hi, I have configure multiple system on Web dispatcher EP and ERP. My issue is our company do not want to publish EP and ERP over the internet but by the web dispatcher uses as a reverse proxy i want to publish the web dispatcher only now my EP calle

  • JMS configuration for clustring

              Hi,           I have a JMS.ear, having jms.war, jms-ejb.jar.           I need to deploy it for clustered environment.           So how to set the targets? what changes needs to be made in the config.xml to incorporate           this.