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.

Similar Messages

  • 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?

  • 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 ();

  • Font setting for the line headings of a numbered list

    I have been setting up Word files which are in outline form with A., 1., a., etc. as the numbering. In Word, the line heading (A., 1., etc.) take on the font and size that I use for the line text. In Pages, it seems to be stuck on a default size that is larger than I want (seems to be 10) and Times New Roman font, which I don't like. I can highlight the line text and change its size and font but the the heading remains the same. I can't find anything in Preferences about this. Is there a control somewhere?
    Message was edited by: Sonic10

    I'm not sure I understand what you want to do, but it sounds like it is something you can solve by creating a new template.
    1. Modify the styles in the Style Drawer in a file so they look like you want them to look.
    2. Save the file as a template.
    3. Use that template to create new files.

  • Using a Variable in SSIS - Error - "Command text was not set for the command object.".

    Hi All,
    I am using a OLE DB Source in my dataflow component and want to select SQL Query from the master table  I have created variables v_Archivequery
    String packageLevel (to store the query).
    <Variable Name="V_Archivequery" DataType="String">
         SELECT a.*, b.BBxKey as Archive_BBxKey, b.RowChecksum as Archive_RowChecksum
         FROM dbo.ImportBBxFbcci a LEFT OUTER JOIN Archive.dbo.ArchiveBBxFbcci b
         ON (SUBSTRING(a.Col001,1,4) + SUBSTRING(a.Col002,1,10)) = b.BBxKey
         Where (b.LatestVersion = 1 OR b.LatestVersion IS NULL)
        </Variable>
    I am assigning this query to the v_Archivequery variable, "SELECT a.*, b.BBxKey as Archive_BBxKey, b.RowChecksum as Archive_RowChecksum
    FROM dbo.ImportBBxFbcci a LEFT OUTER JOIN Archive.dbo.ArchiveBBxFbcci b
     ON (SUBSTRING(a.Col001,1,4) + SUBSTRING(a.Col002,1,10)) = b.BBxKey
    Where (b.LatestVersion = 1 OR b.LatestVersion IS NULL)"
    Now in the OLE Db source, I have selected as Sql Command from Variable, and I am getting the variable, v_Archivequery .
    But when I am generating the package and when running I am getting bewlo errror
     Error at Data Flow Task [OLE DB Source [1]]: An OLE DB error has occurred. Error code: 0x80040E0C.
    An OLE DB record is available.  Source: "Microsoft SQL Native Client"  Hresult: 0x80040E0C  Description: "Command text was not set for the command object.".
    Can Someone guide me whr am going wrong?
    Please let me know where am going wrong?
    Thanks in advance.
    Thankx & regards, Vipin jha MCP

    What happens if you hit Preview button in OLE DB Source Editor? Also you can use the same query by selecting SQL Command option and test.
    Could you try set the Delay Validation = True at Package and re-run ?
    If set the query in variable expression (not in value), then Set Evaluate As Expression = True.
    -Vaibhav Chaudhari

  • I no longer want to merge my work laptop with my icloud account on other devices.  How can I change the setting for the laptop?

    I accidentally agreed to set up my work laptop icloud account to merge with my other devices and want to keep the work information separate.  How can I change the setting for the PC at work?

    Sign out of iCloud.

  • Error when installing 9.0.1.4.0 patch set for the Oracle Database Server.

    Hi to all.
    Currently, i am trying to install patches for portal server.
    The server OS is Sun Solaris 8.
    We are using Oracle9iAS.
    Now, we are installing 9.0.1.4.0 patch set for the Oracle Database Server.
    We managed to install the patch, but have problem with the Post Install Action.
    We managed to run
    -ALTER SYSTEM ENABLE RESTRICTED SESSION;
    -@rdbms/admin/catpatch.sql
    -ALTER SYSTEM DISABLE RESTRICTED SESSION;
    -CONNECT / AS SYSDBA
    -update obj$ set status=5 where type#=29 and owner#!=0;
    -commit;
    But, when we come to the next command, which is to shutdown, it gives us like
    this..
    SQL> update obj$ set status=5 where type#=29 and owner#!=0;
    1402 rows updated.
    SQL> commit;
    Commit complete.
    SQL> shutdown immediate
    Database closed.
    Database dismounted.
    ORA-00604: error occurred at recursive SQL level 1
    ORA-01219: database not open: queries allowed on fixed tables/views only
    We tried to startup the database..it gives us this error..
    SQL> startup
    ORA-01081: cannot start already-running ORACLE - shut it down first
    So, we tried to shutdown again..
    SQL> shutdown immediate
    ORA-01089: immediate shutdown in progress - no operations are permitted
    I been informed that this is maybe a Database problem related. Any ideas?
    Best Wishes,
    Rushdan Md Saad.

    Patchsets could be obtained (only) from http://metalink.oracle.com
    You need to have valid CSI for access.
    P.S: Sorry Werner, I didn't see you post.
    Message was edited by:
    Ivan Kartik

  • The tag handler gridcolumn does not have a setter for the attribute autoExpand specified in the Tag Library Descriptor.

    I recently moved from coldfusion 8 to coldfusion 9 but all the pages with cfgrid: is throwing the following error. Any suggestion would be of great help
    coldfusion.jsp.JRunTagLibraryInfo$NoSuchAttributeException: The tag handler gridcolumn does not have a setter for the attribute autoExpand specified in the Tag Library Descriptor.
    at coldfusion.jsp.JRunTagLibraryInfo.getPropertyType(JRunTagLibraryInfo.java:627)
    at coldfusion.jsp.JRunTagLibraryInfo.buildTagInfo(JRunTagLibraryInfo.java:585)
    at coldfusion.jsp.JRunTagLibraryInfo.getTag(JRunTagLibraryInfo.java:267)
    at coldfusion.compiler.NeoTranslationContext.findTagName(NeoTranslationContext.java:346)
    at coldfusion.compiler.NeoTranslationContext.isKnownTag(NeoTranslationContext.java:222)
    at coldfusion.compiler.CFMLParserBase.isKnownTagName(CFMLParserBase.java:589)
    at coldfusion.compiler.cfml40TokenManager.TokenLexicalActions(cfml40TokenManager.java:6704)
    at coldfusion.compiler.cfml40TokenManager.getNextToken(cfml40TokenManager.java:6586)
    at coldfusion.compiler.cfml40.getToken(cfml40.java:11879)
    at coldfusion.compiler.CFMLParserBase.isTrivialAngleBracket(CFMLParserBase.java:707)
    at coldfusion.compiler.cfml40.jj_3_1(cfml40.java:9392)
    at coldfusion.compiler.cfml40.jj_3_2(cfml40.java:9460)
    at coldfusion.compiler.cfml40.jj_3R_67(cfml40.java:9500)
    at coldfusion.compiler.cfml40.jj_3_86(cfml40.java:8147)
    at coldfusion.compiler.cfml40.jj_3R_92(cfml40.java:8584)
    at coldfusion.compiler.cfml40.jj_3_85(cfml40.java:8641)
    at coldfusion.compiler.cfml40.jj_2_85(cfml40.java:7619)
    at coldfusion.compiler.cfml40.cfml(cfml40.java:4215)
    at coldfusion.compiler.cfml40.cfif(cfml40.java:311)
    at coldfusion.compiler.cfml40.cfml(cfml40.java:4224)
    at coldfusion.compiler.cfml40.cfif(cfml40.java:311)
    at coldfusion.compiler.cfml40.cfml(cfml40.java:4224)
    at coldfusion.compiler.cfml40.cfelse(cfml40.java:442)
    at coldfusion.compiler.cfml40.cfelseif(cfml40.java:374)
    at coldfusion.compiler.cfml40.cfif(cfml40.java:314)
    at coldfusion.compiler.cfml40.cfml(cfml40.java:4224)
    at coldfusion.compiler.cfml40.start(cfml40.java:4664)
    at coldfusion.compiler.NeoTranslator.parsePage(NeoTranslator.java:667)
    at coldfusion.compiler.NeoTranslator.parsePage(NeoTranslator.java:648)
    at coldfusion.compiler.NeoTranslator.parseAndTransform(NeoTranslator.java:401)
    at coldfusion.compiler.NeoTranslator.translateJava(NeoTranslator.java:343)
    at coldfusion.compiler.NeoTranslator.translateJava(NeoTranslator.java:144)
    at coldfusion.runtime.TemplateClassLoader$TemplateCache$1.fetch(TemplateClassLoader.java:418 )
    at coldfusion.util.LruCache.get(LruCache.java:180)
    at coldfusion.runtime.TemplateClassLoader$TemplateCache.fetchSerial(TemplateClassLoader.java :362)
    at coldfusion.util.AbstractCache.fetch(AbstractCache.java:58)
    at coldfusion.util.SoftCache.get_statsOff(SoftCache.java:133)
    at coldfusion.util.SoftCache.get(SoftCache.java:81)
    at coldfusion.runtime.TemplateClassLoader.findClass(TemplateClassLoader.java:591)
    at coldfusion.filter.PathFilter.invoke(PathFilter.java:80)
    at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
    at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:2 8)
    at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
    at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
    at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
    at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
    at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:53)
    at coldfusion.CfmServlet.service(CfmServlet.java:201)
    at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
    at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
    at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42 )
    at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
    at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
    at jrun.servlet.FilterChain.service(FilterChain.java:101)
    at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
    at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
    at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
    at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
    at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
    at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
    at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
    at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
    at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

    Thanks Vishu,
    We are running Coldfusion 9 and attach is the sample code and error message.:
    The tag handler gridcolumn does not have a setter for the attribute autoExpand specified in the Tag Library Descriptor.
    The CFML compiler was processing:
      A cfgrid tag beginning on line 39, column 18.
    The error occurred in E:/Websites/DreData/sobrietytesting/main/Sobrietytesting/Admin/view_users.cfm: line 54
    52 :                     hrefkey="member_id"
    53 :                     bind="cfc:tabledisplay.browseAccessAcountRequests(,,,)"
    54 :                     >
    55 :                    

  • My ipod may have crashed while trying to update new os.4. it;s been trying to restore original setting for the next 10 hours without success. what do I do?

    My ipod touch4 may have crashed in trying to up date to the new ios. 4.3.4. I have not been successful in attempting to retore back  to original setting for the past 10 hours. What do I do next.

    Fix iOS Apps Stuck on “Waiting…” During Download & Install
    Fix iPhone Apps Stuck "Waiting" During Installation

  • How do your turn off the "black and White" setting for the visually impaired?

    How do you turn off the "black and White" setting for the visually impaired?  Also known as the "tripple Click"

    Settings>General>Accessibilty>White on black--> Off

  • My iPad Prefs are set for the side switch to Mute; but the speaker does not mute when the switch is moved down.

    My iPad Prefs are set for the side switch to Mute; but the speaker does not mute when the switch is moved down.

    That setting only works for system sounds like push notifications (emails and the like), some game sounds, keyboard clicks and things like that. If you want to mute all sounds you still have to turn the volume all the way down with the volume switch.

  • AutoCommit Setting for the Microsft OleDB Provider for Oracle(MSDAORA)

    Hi,
    The default setting for the AutoCommit(MSDAORA) is "On". can any one please tell me how to set this Off.
    thanks

    To use 32 bit oraoledb, you'll need to set IIS to run in 32 bit mode.
    Or, install 64 bit oledb/client instead.
    Hope it helps,
    Greg

  • HT4110 What is the best battery setting for the MacBook Pro 13 Retina display?

    I want to know the best setting for the battery for the MacBook Pro 13 Retina display.

    To add just a little
    Keep it plugged in when near a socket so you keep the charging cycles down on your LiPo (lithium polymer) cells / battery, but not plugged in all the time. When not being used for several hours, turn it off.
    And best "tip" is if its near a socket,...plug it in as long as you can (especially at home) since cycle count on the battery are the "miles that wear out the tires (battery)", however again, not plugged in all or most of the time.
    http://www.apple.com/batteries/notebooks.html
    "Apple does not recommend leaving your portable plugged in all the time."
    General rule to remember of Lithium batteries is:
    Never drain them LOW  & dont always/often store them HIGH
    While cycle count is commonly seen to be the “miles” on your Lithium Ion pack cell in your Macbook, which they are, this distinction is not a fine line at all, and it is a big misconception to “count charge cycles”
    *A person who has, for example, 300 charge cycles on their battery and is recharging at say 50-60% remaining of a 100% charge has better battery usage and care than another person who has 300 charge cycles at say 15% remaining on a 100% charge. 
    DoD (depth of discharge) is far more important on the wear and tear on your Macbook battery than any mere charge cycle count.  *There is no set “mile” or wear from a charge cycle in general OR in specific.    As such, contrary to popular conception, counting cycles is not conclusive whatsoever, rather the amount of deep DoD on an averaged scale of its use and charging conditions.
                              (as a very rough analogy would be 20,000 hard miles put on a car vs. 80,000 good miles being something similar)
    *Contrary to some myths out there, there is protection circuitry in your Macbook and therefore you cannot overcharge it when plugged in and already fully charged
    *However if you don’t plan on using it for a few hours, turn it OFF (plugged in or otherwise) ..*You don’t want your Macbook both always plugged in AND in sleep mode       (When portable devices are charging and in the on or sleep position, the current that is drawn through the device is called the parasitic load and will alter the dynamics of charge cycle. Battery manufacturers advise against parasitic loading because it induces mini-cycles.)
    Keeping batteries connected to a charger ensures that periodic "top-ups" do very minor but continuous damage to individual cells, hence Apples recommendation above:   “Apple does not recommend leaving your portable plugged in all the time”, …this is because “Li-ion degrades fastest at high state-of-charge”.
                        This is also the same reason new Apple notebooks are packaged with 50% charges and not 100%.
    LiPo (lithium polymer, same as in your Macbook) batteries do not need conditioning. However...
    A lot of battery experts call the use of Lithium cells the "80% Rule" ...meaning use 80% of the charge or so, then recharge them for longer overall life.
    Never let your Macbook go into shutdown and safe mode from loss of power, you can corrupt files that way, and the batteries do not like it.
    The only quantified abuse seen to Lithium cells are instances when often the cells are repeatedly drained very low…. key word being "often"
    Contrary to what some might say, Lithium batteries have an "ideal" break in period. First ten cycles or so, don't discharge down past 40% of the battery's capacity. Same way you don’t take a new car out and speed and rev the engine hard first 100 or so miles.
    Proper treatment is still important. Just because LiPo batteries don’t need conditioning in general, does NOT mean they dont have an ideal use / recharge environment. Anything can be abused even if it doesn’t need conditioning.
    From Apple on batteries:
    http://support.apple.com/kb/HT1446
    http://www.apple.com/batteries/
    Storing your MacBook
    If you are going to store your MacBook away for an extended period of time, keep it in a cool location (room temperature roughly 22° C or about 72° F). Make certain you have at least a 50% charge on the internal battery of your Macbook if you plan on storing it away for a few months; recharge your battery to 50% or so every six months roughly if being stored away. If you live in a humid environment, keep your Macbook stored in its zippered case to prevent infiltration of humidity on the internals of your Macbook which could lead to corrosion.
    Considerations:
    Your battery is subject to chemical aging even if not in use. A Lithium battery is aging as soon as its made, regardless.
    In a perfect (although impractical) situation, your lithium battery is best idealized swinging back and forth between 20 and 85% SOC (state of charge) roughly.
    Further still how you discharge the battery is far more important than how it is either charged or stored short term, and more important long term that cycle counts.
    Ultimately counting charge cycles is of little importance.  Abuse in discharging (foremost), charging, and storing the battery and how it affects battery chemistry is important and not the ‘odometer’ reading, or cycle counts on the battery. 
    Everything boils down to battery chemistry long term, and not an arbitrary number, or cycle count.
    Keep your macbook plugged in when near a socket since in the near end of long-term life, this is beneficial to the battery.
    Peace

  • Where is the privacy setting for the trial version of cs6 photoshop. I would like to turn it off.

    Where is the privacy setting for the trial version of cs6 photoshop. I would like to turn it off. The answers given by 'Staff' are incorrect - it is NOT locared within Help/Adobe Product Improvement Program! I use W7 64bit.

    daveteauk2 wrote:
    Where is the privacy setting for the trial version of cs6 photoshop. I would like to turn it off. The answers given by 'Staff' are incorrect - it is NOT locared within Help/Adobe Product Improvement Program! I use W7 64bit.
    You are correct.
    The privacy settings will be those of the "trial experience" and that has nothing to do with the APIP.
    Maybe this image will help:

  • I can record and hear me recording through the computer's built in mic, but can't get the external mic and headphones to work., The preferences are set for the external mic and headphones...

    I can record and hear me recording through the computer's built in mic, but can't get the external mic and headphones to work., The preferences are set for the external mic and headphones...

    What operating system are you using? Is it on a Mac or a PC? Which preferences are set for external mic/headphones, Audition's or the computers?

Maybe you are looking for

  • Can I combine multiple threads from the same contact in iMessage?

    iMessage displays multiple threads for the same contact.  Its very confusing and has resulted in lost messages.  I've tried changing a number of settings but to no avail.  Seems to require everyone in my contact list to eliminate all their email addr

  • Adobe Acrobat 9 Pro Update

    Hi, i just new installed my MacBook and tried to install Adobe Acrobat 9 Pro. It worked fine ... So just now I'm running on 9.0.0 I noticed that there is a problem with this version when running on mavericks. After I asked Google I found out that I s

  • Win 7 Clipboard clears contents when opening a new application or window

    There are similar posts on this issue, but I see none with a satisfactory fix. I have a brand new Dell Laptop, running Win 7 Pro 64-bit SP1. If I copy anything to the Clipboard, it works fine *IF* where I want to paste it is already open. However, If

  • URGENT HELP! Resetting OS

             I've recently been handed down a MacBook Pro w/o its installation cds. I wanted to start fresh with it so I've used the cds (10.5.8) that came with my iMac (Intel Core 2 Duo) to reset everything in my new old Mac. The MacBook Pro says it can

  • Div image background not showing

    Hi I am trying to give a div a background image and then place tables etc in the div.  The trouble is the image does not show up.   Any help greatly appreciated.  Regards, Matt.  (Here is the html, followed by the css...) <!DOCTYPE html PUBLIC "-//W3