Best technique for laying out a JPanel with sub panels...

Okay, you're probably going to think this is a nit-picky question, but I seem to do it different each time I have to solve this problem, and neither of them feels like they're obviously the "right" way to do things, so I'm asking for how you all do them.
Suppose I'm making a panel that's going to have several other panels on it. For example, let's say that the main JPanel is going to use BorderLayout and then there's going to be a sub-panel with a bunch of radiobuttons.. and another with some textboxes, and another with some jbuttons, etc.
There are a few ways you can do it:
Method #1
1 Instantiate main JPanel
2 Instantiate a sub-panel
3 add() the sub-panel to the main (before it has anything)
4 Populate the sub-panel with compnents
5 Repeat 2-4 for all other sub-panels
Method #2
1 Instatiate main JPanel
2 Instantiate a sub-panel
3 add() it to the main panel
4 repeat 2-3 for all sub-panels
5 populate the first sub-panel with components
6 Repeat #5 for all sub-panels
Method #3
1 Instantiate a sub-panel
2 Populate the sub-panel with components
3 Repeat 1-2 for all sub-panels
4 Instantiate main JPanel
5 Add populated sub-panel to main JPanel
6 Repeat #5 for all sub-panels
Method #4 (same as Method #1 except #3 and #4 are switched)
1 Instantiate main JPanel
2 Instantiate a sub-panel
3 Populate the sub-panel with components
4 add() populated sub-panel to main panel
5 repeat 2-4 for all sub-panels
They'll all work just fine when you initially write them. What I'm after is the one which:
1) Is the most readable later, and
2) Is easiest to make changes to if you want to change the way your overall panel looks (ie, least chance of having something go wrong because you didn't realize that you need to make a change in two different places in the code instead of one, etc).
Of these methods, do any of them strike you as either "Sure, that's the only way to really do it!" or "Oh man, if you did it *that* way, you're in for major headaches"?
Thanks in advance,
- Joe

Well, my code generally would look something like this:
add(createToolBar(), BorderLayout.NORTH);
add(createApplicationPanel(), BorderLayout.CENTER);
add(createStatusBar(), BorderLayout.SOUTH);The createApplicationPanel might then be broken down into sub methods depending on the complexity of the application.
So I guess that would be your method 4.
The key point to remember is that you want create and add all the components and panels BEFORE you do your frame.pack() and frame.setVisible(), then you shouldn't have any layout problems.

Similar Messages

  • Where to find the best application for cleaning out my MacBook Air with OS X 10.7.5? I've been using MacKeeper but believe it's slowing down my laptop considerable.

    where to find the best application for cleaning out my MacBook Air with OS X 10.7.5? I've been using MacKeeper but believe it's slowing down my laptop considerable. Thank you.

    How to maintain a Mac
    1. Make redundant backups, keeping at least one off site at all times. One backup is not enough. Don’t back up your backups; make them independent of each other. Don’t rely completely on any single backup method, such as Time Machine. If you get an indication that a backup has failed, don't ignore it.
    2. Keep your software up to date. In the Software Update preference pane, you can configure automatic notifications of updates to OS X and other Mac App Store products. Some third-party applications from other sources have a similar feature, if you don’t mind letting them phone home. Otherwise you have to check yourself on a regular basis. This is especially important for complex software that modifies the operating system, such as device drivers. Before installing any Apple update, you must check that all such modifications that you use are compatible.
    3. Don't install crapware, such as “themes,” "haxies," “add-ons,” “toolbars,” “enhancers," “optimizers,” “accelerators,” "boosters," “extenders,” “cleaners,” "doctors," "tune-ups," “defragmenters,” “firewalls,” "barriers," “guardians,” “defenders,” “protectors,” most “plugins,” commercial "virus scanners,” "disk tools," or "utilities." With very few exceptions, this stuff is useless, or worse than useless. Above all, avoid any software that purports to change the look and feel of the user interface.
    The more actively promoted the product, the more likely it is to be garbage. The most extreme example is the “MacKeeper” scam.
    As a rule, the only software you should install is that which directly enables you to do the things you use a computer for — such as creating, communicating, and playing — and does not modify the way other software works. Use your computer; don't fuss with it.
    Safari extensions, and perhaps the equivalent for other web browsers, are a partial exception to the above rule. Most are safe, and they're easy to get rid of if they don't work. Some may cause the browser to crash or otherwise malfunction.  Some are malicious. Use with caution, and install only well-known extensions from relatively trustworthy sources, such as the Safari Extensions Gallery.
    Never install any third-party software unless you know how to uninstall it. Otherwise you may create problems that are very hard to solve.
    4. Beware of trojans. A trojan is malicious software (“malware”) that the user is duped into installing voluntarily. Such attacks were rare on the Mac platform until sometime in 2011, but are now increasingly common, and increasingly dangerous.
    There is some built-in protection against downloading malware, but you can’t rely on it — the attackers are always at least one day ahead of the defense. You can’t rely on third-party protection either. What you can rely on is common-sense awareness — not paranoia, which only makes you more vulnerable.
    Never install software from an untrustworthy or unknown source. If in doubt, do some research. Any website that prompts you to install a “codec” or “plugin” that comes from the same site, or an unknown site, is untrustworthy. Software with a corporate brand, such as Adobe Flash Player, must be acquired directly from the developer. No intermediary is acceptable, and don’t trust links unless you know how to parse them. Any file that is automatically downloaded from a web page without your having requested it should go straight into the Trash. A website that claims you have a “virus,” or that anything else is wrong with your computer, is rogue.
    In OS X 10.7.5 or later, downloaded applications and Installer packages that have not been digitally signed by a developer registered with Apple are blocked from loading by default. The block can be overridden, but think carefully before you do so.
    Because of recurring security issues in Java, it’s best to disable it in your web browsers, if it’s installed. Few websites have Java content nowadays, so you won’t be missing much. This action is mandatory if you’re running any version of OS X older than 10.6.8 with the latest Java update. Note: Java has nothing to do with JavaScript, despite the similar names. Don't install Java unless you're sure you need it. Most people don't.
    5. Don't fill up your boot volume. A common mistake is adding more and more large files to your home folder until you start to get warnings that you're out of space, which may be followed in short order by a boot failure. This is more prone to happen on the newer Macs that come with an internal SSD instead of the traditional hard drive. The drive can be very nearly full before you become aware of the problem. While it's not true that you should or must keep any particular percentage of space free, you should monitor your storage consumption and make sure you're not in immediate danger of using it up. According to Apple documentation, you need at least 9 GB of free space on the startup volume for normal operation.
    If storage space is running low, use a tool such as the free application OmniDiskSweeper to explore your volume and find out what's taking up the most space. Move rarely-used large files to secondary storage.
    6. Relax, don’t do it. Besides the above, no routine maintenance is necessary or beneficial for the vast majority of users; specifically not “cleaning caches,” “zapping the PRAM,” "resetting the SMC," “rebuilding the directory,” "defragmenting the drive," “running periodic scripts,” “dumping logs,” "deleting temp files," “scanning for viruses,” "purging memory," "checking for bad blocks," "testing the hardware," or “repairing permissions.” Such measures are either completely pointless or are useful only for solving problems, not for prevention.
    The very height of futility is running an expensive third-party application called “Disk Warrior” when nothing is wrong, or even when something is wrong and you have backups, which you must have. Disk Warrior is a data-salvage tool, not a maintenance tool, and you will never need it if your backups are adequate. Don’t waste money on it or anything like it.

  • What is the best technique for resetting a view?

    I was wondering what is the best technique for resetting the initial state of a view?
    I am creating a form and want to provide a reset button for the user.  I could write an initialize() method that my action handler calls, but I am wondering if the framework already provides this functionality in a more elegant way.
    If I write an initialize method, then I have to manually populate my fields with my context mappings in my initialize() code to mimic what happens automatically by the framework the first time the view is called.  This seems prone to error since this is duplicating the mapping logic.
    Michael

    Hi,
    Even though it boils down to the same logic, for consistency sake it is good to have the initialization logic coded in the inbound plug method and then to call the outbound plug on reset.This make more sense when you have multiple navigation possible to the same view through multiple inbound plugs.
    Else, have an initialization method.
    PS: check whether the reset() method of IWDContext make sense. This is helpful when you have remove dynamically added nodes and attributes.
    Thanks and Regards,
    Sam Mathew

  • What is the best practice for using the Calendar control with the Dispatcher?

    It seems as if the Dispatcher is restricting access to the Query Builder (/bin/querybuilder.json) as a best practice regarding security.  However, the Calendar relies on this endpoint to build the events for the calendar.  On Author / Publish this works fine but once we place the Dispatcher in front, the Calendar no longer works.  We've noticed the same behavior on the Geometrixx site.
    What is the best practice for using the Calendar control with Dispatcher?
    Thanks in advance.
    Scott

    Not sure what exactly you are asking but Muse handles the different orientations nicely without having to do anything.
    Example: http://www.cariboowoodshop.com/wood-shop.html

  • What is the best option for tethering my IPhone 4s with my iPad? (the iPad is wifi only)

    What is the best option for tethering my IPhone 4s with my iPad? (the iPad is wifi only)

    #1. Understand that if you switch carriers, you can NOT take your existing iPhone with you. It won't work. You will need to purchase a new one.
    #2. Your only choices are Sprint and Verizon. Decide who has the better coverage in your area. Keep in mind that you will NOT be able to get simultaneous voice and 3G data on either of these, as their CDMA networks do not support it. The U.S. T-Mobile network is not supported and is not fully compatible with the iPhone as it operates on a rarely used frequency compared to the rest of the world.
    #3. What in the world are "niners"? Do you mean you want to be able to keep your existing "phone numbers"? If so, that should be no problem. Most numbers in the US are now portable.
    #4. Consider WHY you want to switch. If the issue is really price, you're not going to see much of a difference. A few dollars a month at best for comparable voice and data plans.

  • What is the best software for burning a large slideshow with 500 photos and music to DVD?

    What is the best software for burning a large slideshow with 500 photos and music to DVD?

    Are you talking about strictly burning an already put-together slideshow or composing one and then burning it?
    My all time favorite slide show maker is Photo to Movie; you can then burn it from there or get it into iMovie and/or iDVD for the "finishing" touch. My favorite burn software is Toast, although you can use iMovie, iDVD, and Finder as well.
    http://www.lqgraphics.com/software/phototomovie.php
    http://www.roxio.com/enu/products/toast/titanium/

  • How to print out a JPanel with its components

    Hello,
    I want to print out a JPanel where several components are placed in. The problem is just that neither the printAll() method nor the print() method works to do so. There's always just a print of the empty JPanel. Is there in general a possibility to print out a JPanel with its components or are I'm on the wrong way ?
    Thanx,
    Findus

    I just posted this link and it works here:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=361445&tstart=0&trange=15

  • Vi's with sub panel

    hi
    i want to run an aplication on fp-2010 which have sub panels(panel embedding)
    but i got the following problems
    1.vi's with sub panel are not loaded on fp-2010
    2.and not supported by Lab VIEW Real Time
    can any one help me in this regard or suggest any other method that i run my application with fp-2010
    OR can i use any other tecnique which give the same functionality as sub panels and compatible Lab VIEW Real Time
    regards
    mazhar

    duplicate post

  • What is the best way to lay out color-coded Excel data in InDesign?

    I’ve been away from layout for some time. I now need to lay out color-coded Excel data (3 columns, 200 rows) in InDesign 5.5. The data will need to be in alpha order and each row will be color coded, with a color key at the top of the page. What is the best way to lay this out? Should I use the table tool and create a new style for each color that I need to use?
    Thanks for your help.

    I think this will work in CS3.
    Start off by inserting Styles of WEEK, Mon to Friday (as per left)
    Set the Week No. to Bullets and Numbering and insert as per screen shot
    Do the same for Days Monday through to Sunday
    Also set up Monday style NEXT STYLE to be Tuesday
    When you get to Sunday - loop the Styles back to WEEK style.
    Then as per first screen shot you just have to insert RETURNS all the way down to initiate the style.

  • Best way to lay out this scrapbook

    I need some advice about the best way to go about this. I have a client who basically want me to publish her scrapbook. It's full of all sorts of color and b/w photos, drawings, newspaper clippings, you name it. I was thinking I should scan each page (8 1/2 x 11) as a separate pdf, then place each pdf as a separate page in the ID document. After about 10 pages or so the ID document is so bogged down that it takes half a minute just to nudge a frame. I hate to think of what things would be at 200 pages. Even if I divided the book up into 20 or 40 separate documents then reassembled them as a book, it would probably be so unwieldy that I wouldn't even be able to scroll the pages. Once this is done it has to be submitted to the printer as a pdf.

    What the client has done is lay out her original photos on a piece of 8 1/2 x 11, xerox it, then type captions next to the xeroxed photos, then attach the original photos over the top of the xeroxes. Two pages are then placed back to back in a clear plastic sleeve, which, along with another 199 sleeves, goes into a ring binder. I’m laying the book in ID (CS3, btw) because I want to add page numbers and some of the pages need to be centered or otherwise moved around so that I can maintain the printer’s minimal margins (the typing and placement of the illustrations on the original page sometimes goes to the very edge). Also, as I scan I'm trying to cut out toner shadows and other blemishes on the original pages. I’ve been scanning using my scanner’s software (Epson Perfection V200). The setting for the image quality of the outputted scan is 24-bit color at 300 dpi (pages with just text are scanned as black & white, 300 dpi, pages with only black & white photos are scanned as grayscale). If I want to do more editing (like cleaning up more blemishes) I open the pdfs in Photoshop. That way I can also change the color mode to CMYK before I save the file. Should I be scanning directly into Photoshop, then? I don’t scale the pdfs in ID because I know that can affect the resolution. I’ll try making tifs instead of pdfs.

  • What's the best solution for audio out of sound files from a MacBook Air to both an amplifier and to a subwoofer amplifier? I'm using the MBA to play sound files for worship services at our church.

    I have a MacBook Air (13", 1.7GHz, 8GB RAM, 500GB SSD) that I'll be using to play sound files (primarily organ and piano) for worship services at my church. We'll be using a QSC RMX2450 650 Watts/Channel amplifier with Community CPL-27 speakers and also a JBL SUB 250P powered subwoofer with its own amplifier. What's the best option for getting sound out from the Mac to both of these amplifiers? 

    if you work with own recorded sounds you might wanna have a music program where you want to work with samples, steinberg has got very good ones (so they say)... but their really really ( ²) expensive(that's why almost no one haves them), magix haves good ones too bu their more for 'unprofessional' use, ableton haves really good ones too and they're not to difficult to use (if you know a bit of those programs you learn very quickly) and if you don't get them, there is a sort of manual built in it which explains and lets you do things to start (basics)
    i hope this helped, btw stereo speakers are always better if you buy good ones (no pc speakers), but if you don't think you need them, don't buy them...
    so again, i hope you have some ideas now

  • Best methods for importing artwork via Illustrator with tranparency?

    I'm new to Final Cut Pro and am tryin to figure out the best methods for importing artwork via Illustrator. So far, I've been saving the artwork as a transparent PNG, but I feel like there should be a better way. Any help would be greatly appreciated.
    Thanks,
    Mike
    MacBook Pro   Mac OS X (10.4.8)  

    Hi:
    Ussually I have to rebuild in AI the company logo (I use to work for industries) to include in FCP edit.
    - If you have CS2, open Photoshop and create a new file using the right preset (i.e. DV PAL) using transparent background. That creates a PSD empty file with all attributes you need (pixels dimensions and aspect ratio) to use later in FCP.
    - Select your work (i.e. the final logo) in the AI canvas and copy it.
    - Paste it in the empty PSD file as "vextor information" (I don't remember right now the exact words!). That way you can resize it in the PSD file without loosing quality.
    - The better ir deciding the size NOW in Photoshop, or create sveral version in different sizes. Yuo'll get better quality id you make the resizings in Photoshop rather that doing a scale in FCP timeline.
    - Once your logo is in the right dimension into the PSD file, save a copy and flatten all layers keeping the transparent background. If you don't need the layers during editing in FCP, you better have all layers flattened.
    - Import that file in FCP.
    That's my workflow, but probably you'll find different flavors here!
      Alberto

  • Best headphones for working out?

    I just got my first ipod (5G) so I am not familiar with what headphones create the best sound for it...I will mainly be using it while I work out so I won't want to use big 'ole "earmuffs"...any suggestions?

    I've tried many, many different kinds of phones with my iPods over the last 2 years. I own several isolater-style phones from SHURE , ER, and Sony and they sound superb but for working out isolaters reflect too much of my breathing sounds. They also feel mushy in your ear after you start to perspire.. Unless your club has really loud music to tune out, I'd avoid isolator-types, and if you do, pick the soft plastic tips over the foam ones!
    Believe it or not, the best listening experience I've found for working out is the Koss KSC-75 Sport Clip-On Headphones.
    These clip on to your ears but they are completely comfortable- unlike every other clip-on type I've ever tried.
    They currently retail for $13 at some retail websites, and the sound is tremendous. I enjoy listening to music on these more than even my isolators. They are that comfortable and great-sounding.
    heres a review on a website that does a good job of reviewing phones by usage categories.
    http://www.headphone.com/guide/by-application/exercising/
    I'd give them a try-

  • Best headphones for working out? Shure E2C or Bose In ear TriPort?

    I want some good headphones for my Nano (2nd gen) while I'm working out (jogging).
    My wife gave me the Bose In Ear TriPort for Xmas, and while the sound is very good, the right tends to "loosen up" easily. I can return within 30 days, hence I need opinions on other headphones for working out.
    I have read positive reports on the Shure E2C and the Sennheiser MX 70.
    Does anybody have any experience using these headphones during workouts? I am looking for great sound but more importantly, a set of in ear phones that stay secure while working out. I do not want heavy bass either.
    All opinions are appreciated.
    Thanks

    I have the E2c and they are great. The only caveat I have are the sleeves. It comes with 3 types, flex, soft flex, and foam. They all come in 3 sizes also. The best fit that works for me are the foam. They stay in your ear and provide excellent isolation.
    Here is the site to read about them.
    http://www.shure.com/PersonalAudio/Products/Earphones/ESeries/uspa_E2c_content?tab=rewardsawards

  • FI  TABLES FOR LAY-OUT

    hi GUYS
    i am working on FI Lay-out, and want to print product hierarchy, Sales organisation and country for Document number. plz help me to find these fields.
    selection screen is document no, company code, fiscal year.
    thanks,
    sum

    Hi,
    Kindly check the following links:
    http://www.erpgenie.com/sap/abap/tables_fi.htm
    http://www.erpgenie.com/sap/abap/tables_sd.htm
    http://www.erpgenie.com/sap/abap/tables_mm.htm
    http://www.erpgenie.com/sap/abap/tables.htm
    Check
    Billing header table:
    VBRK
    Fields: VBELN - sales doc number, VKORG - sales Org.
    Billing item table:
    VBRP
    Fields: PRODH - Product Hierarchy
    Hope this helps!
    Best regards,
    Thangesh

Maybe you are looking for