Help! How can I lay out forms?

Hi:
I've tried everything and I just can't get Java to lay out a form for me.
I'm currently using TableLayout:
http://www.clearthought.info/software/TableLayout/
I expect the buttons to be in the bottom right hand corner of the form.
Only one shows up and it's apparantly over top the other one. They're at the top of the form.
What am I doing wrong?
public static void main(String[] args)
        btnOne = new JButton(" One ");
        btnOne.setPreferredSize(new Dimension(80, 25));
        btnTwo = new JButton(" Two ");
        btnTwo.setPreferredSize(new Dimension(80, 25));
        lbOne = new JLabel("Top Label");
        lbTwo=  new JLabel("Second Label");
       double size[][] =
            {{TableLayout.FILL, 200},
             {0.05, TableLayout.FILL, 25}};
        pnExt = new JPanel(new TableLayout(size));
        pnExt.setPreferredSize(new Dimension(775, 575));
        double sizeLbl[][] =
            {{250},
             {0.05, TableLayout.FILL, 25}};
        pnLabel = new JPanel(new TableLayout(sizeLbl));
        pnLabel.add(lbOne, "0, 0, l, t");
        pnLabel.add(lbTwo, "0, 0, l, t");
         double sizeBtn[][] =
            {{150},
             {TableLayout.FILL, 25, 25}};
        pnButtons = new JPanel(new TableLayout(sizeBtn));
        pnButtons.setPreferredSize(new Dimension(125, 550));
        pnButtons.add(btnOne, "0, 1, r, b");
        pnButtons.add(btnTwo, "0, 2, r, b");
        pnExt.add(lbOne, "0, 0, l, t");
        pnExt.add(pnLabel, "0, 1, l, t");
        pnExt.add(pnButtons, "1, 0");
        fme = new JFrame("My Test");
        fme.setSize(800, 600);
        fme.getContentPane().add(pnExt, BorderLayout.WEST);    
        fme.show();
    }

I've never used TableLayout, but here is some code for a common situation. Suppose you want components arranged like this:
label component (say text field or button)
label component
label component
import java.awt.*;
import javax.swing.*;
public class LayoutExample {
    public static void main(String[] args) {
        JPanel p = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.NORTH;
        gbc.insets = new Insets(0,5,0,0);
        //row 0
        gbc.gridy = 0;
        gbc.gridx = 0;
        p.add(new JLabel("label 0", JLabel.RIGHT), gbc);
        gbc.gridx = 1;
        p.add(new JTextField("field row 0", 20), gbc);
        //row 1
        gbc.gridy = 1;
        gbc.gridx = 0;
        p.add(new JLabel("label 1", JLabel.RIGHT), gbc);
        gbc.gridx = 1;
        p.add(new JTextField("field row 1", 20), gbc);
        //row 2
        gbc.gridy = 2;
        gbc.gridx = 0;
        p.add(new JLabel("longer label 2", JLabel.RIGHT), gbc);
        gbc.gridx = 1;
        p.add(new JButton("row 2"), gbc);
        //row 3
        gbc.gridy = 3;
        gbc.weighty = 100;
        gbc.gridx = 0;
        p.add(new JLabel("label 3", JLabel.RIGHT), gbc);
        gbc.gridx = 1;
        p.add(new JButton("row 3"), gbc);
        display("LayoutExample", p);
    static void display(String title, Component c) {
        JFrame f = new JFrame(title);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(c);
        f.pack();
        f.setLocationRelativeTo(null);
        f.show();
}Resize the frame. the components remain centred horizontally but anchored to the north (that's the effect of weighty).
Of course, your mileage may vary, but don't give up on GridBagLayout. It reminds me of that 60's song, "If you want to be happy for the rest of your life (get yourself and ugly wife)"...

Similar Messages

  • How can I lay out a newspaper look using a photo?

    How can I lay out a newspaper look and incorporate a photo?
    Content to include:  Michelson/Draper Weekender
                                       Nuptual Edition
    date info
    Headline
    Photo
    Articles
    Schedule of events
    Possibly be able to fold

    I recommend Apple's Pages app.  Here is a screen shot from Pages' template chooser:

  • How can I recovered a form that I delete by mistake?

    I nee someone help, How can I recovered a form that I create and later on I deleted by mistake? Thank you in advance for your prompt answer

    Hi;
    I am sorry to say that there isn't any method to recover a deleted form.  There is a confirmation dialog saying that this is a permanent deletion to ensure that is what you want to do, once you've confirmed the form is really deleted and not recoverable.
    Thanks,
    Josh

  • HT4865 I just bought this ipad and cannot log out from icloud because i dont have the password.how can i log out from icloud?need help

    I just bought this ipad and cannot log out from icloud because i dont have the password.how can i log out from icloud?need help

    You need to return it to the seller and get your money back.  You cannot reset or use the device with another AppleID installed unless you know the password for that ID.
    If the device has been jailbroken, no one on here can give you any further help...the Terms of Use prohibit us from doing so.

  • Help! How can I take out the mini-disc stuck in mac?

    Help! How can I take out the mini-disc stuck in mac?
    I insert it into the mac, but the OS cannot load the disc and the disc cannot be ejected even i pressed the "eject" button.

    This happened to a family members macbookpro. A mini-cd inserted, couldn't be mounted or ejected by the drive.
    I cut a rectangle from a cereal box about two inches wide and 6 inches long. Abour an inch and half from one end in the middle I cut a notch and bent it down a little.
    I................I
    I................I
    I....I__I....I
    I................I
    I................I
    I................I
    I................I
    I................I
    I................I
    I................I
    I................I
    I................I
    I________I
    I then inserted it slowly into the drive notch down and slowly pulled out. I did this few times and caught the mimi-cd and removed it. The drive has worked flawlessly for several years
    A few days after this happened I was in BestBuy and an Apple rep was there displaying new Apple products. I asked him about it and he said they have a tool that ***** it out.

  • I just lost my iphone5 in a foreign country. Was not able to register it with icloud and have not installed the findmy iphone app. How can i wipe out my data remotely without these setups? Please help!

    I just lost my iphone5 in a foreign country. Was not able to  previously register it with icloud and have not installed the findmy iphone app. How can i wipe out my data remotely without these setups? Is there any good app i can use to track it? Please help!

    No, nothing you can do to track it if you did not take any measures before the loss.

  • How can I embed a form on my website and set up a submit button so that when people fill out and click Submit, the filled form will be emailed to me as an attached pdf file?

    How can I embed a form on my website and set up a submit button so that when people fill out and click Submit, the filled form will be emailed to me as an attached pdf file?
    Thank you!

    Hi;
    That is not a workflow that is supported by the Adobe forms solutions at this time.
    Thanks,
    Josh

  • How can I get a stripped screw out of the bottom of my iPhone?? I need help, How can I get a stripped screw out of the bottom of my iPhone?? I need help

    How can I get a stripped screw out of the bottom of my iPhone?? I need help, How can I get a stripped screw out of the bottom of my iPhone?? I need help

    Try asking at ifixit.com. The iPhone is not considered user servicable. You're not going to get much help on an Apple sponsored forum.

  • Hi ! I got an iPhone 5 from someone who I don't know the real owner. Then I wanna change iCloud on it, but I don't know the password of owner. How can I log out that iCloud account without password ? Please help me, thank you

    Thank you, please help me !

    How can I log out that iCloud account without password ?
    You can't.
    Return the phone to whoever you bought it from and get a refund. Without the previous owners password you will not be able to enter your own iCloud acount, and when you update the phone, you won't be able to re-activate it as it will be locked to the previous owners account.
    You should've checked the phone was not locked to someone else's iCloud account BEFORE buying it.
    Instructions here: http://support.apple.com/kb/ht5818

  • I have my personal music (not purchased from Itunes) stored in two locations, on my PC and on an external HD. How can I find out which directory itunes uses to access this music? I am using Itunes version 11.4.0.18. Thanks

    I have my personal music (not purchased from Itunes) stored in two locations, on my PC and on an external HD. How can I find out which directory itunes uses to access this music? I am using Itunes version 11.4.0.18. Thanks

    Many thanks JEM24 for your help.  Ive just spent the best part of six hundred pounds on a new Sony Rx100m2 compact camera, so I have no interest in the Ipods camera at all really. I doubt Ill be watching many videos on it as Im very lucky in that I have a good Android tablet. Its more as a stock music player that Ill be buying the Ipod for, if indeed I do end up buying one. I dont like the idea of paying the exorbitant amount added for more memory space that Apple along with most other companies charge. In fact I read an article on this very subject just yesterday in the tech section of Flipboard. It stated in the article that in the case of the Iphone  the actual cost of each additional  gigabyte of storage  to Apple et al is something in the order of 60p.. This is certainly not reflected in the price us the customer has to pay at the till.. Its for this reason primarily that Apple in particular, because their products do not allow adding expandable memory of your own in the form of cheap to buy cards, that nobody in their right mind buys the 64gig etc Iphones..I am aware that we are discussing my potential purchase of an Ipod Touch here but you see my point. Many thanks again though for helping me.

  • How can I take out my credit card number from purchasing anymore app

    How can I take out my credit card number from the App Store to prevent purchasing anymore apps

    How to Get Apps From the App Store Without a Credit Card
    http://ipadhelp.com/ipad-help/how-to-get-free-apps-from-the-app-store-without-a- credit-card/
    Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card
    http://support.apple.com/kb/ht2534
    Why can’t I select None when I edit my payment information?
    http://support.apple.com/kb/ts5366
    If None is not available - On your computer launch iTunes and click “iTunes Store” in the left navigation pane. Click the “down arrow” next to your name at the top right side of the page and click “Account.” Enter your username and password and click “View Account” to log into your account information. Next to your Payment Type, click “Edit.” Select the “None” button and click “Done.” Confirm that your card has been removed by returning to the Apple account information screen. Under Payment Type, it should say that there is no credit card on file.
    iTunes Store: Changing your payment information
    http://support.apple.com/kb/HT1918
    iTunes Store Accepted Forms of Payment
    http://support.apple.com/kb/HT5552
     Cheers, Tom

  • I forgot my security questions for itunes, how can i find out my answers?

    i forgot my security questions for itunes, how can i find out my answers?

    Alternatives for Help Resetting Security Questions and/or Rescue Mail
         1. If you have a valid rescue email address, then use this procedure:
             Rescue email address and how to reset Apple ID security questions.
         2. Fill out and submit this form. Select the topic, Account Security. You must
             have a Rescue Email to use this option.
         3. This is the only option if you do not already have a valid Rescue Email.
             These are telephone numbers for contacting Apple Support in your country.
             Apple ID- Contacting Apple for help with Apple ID account security. Select
             the appropriate country and call. Ask to speak to the Account Security Team.
         4. Account security issues almost always require you to speak directly to an
             Apple representative to securely establish your identity as the account holder.
             You can set it up so that Apple calls you, either immediately or at a time
             convenient to you.
                1. Go to www.apple.com/support.
                2. Choose Contact Support and click Contact Us.
                3. Choose Other Apple ID Topics and choose the appropriate topic for
                    your issue.
                4. Follow the onscreen instructions.
             Note: If you have already forgotten your security questions, then you cannot
             set up a rescue email address in order to reset them. You must set up
             the rescue email address beforehand.
    Your Apple ID: Manage My Apple ID.
                            Apple ID- All about Apple ID security questions.

  • How can i print out the waveform chart?

      hello everybody,
    how can i print out the "waveform chart". can i do it just push the button. ( example; stop button is stop the program etc..)
    i checked the NI examples but i can't understand. i'm new to the Labview.
    pls help me.
    i added the my program
    look forward your reply
    regards from turkey...
    Message Edited by hknmkt on 05-29-2008 04:15 AM
    Attachments:
    29.05.2008_11.vi ‏37 KB

        hi jim,
    i tried the program but it's not running. When i run the program, it's print out without run the program
    i added the printed file.
    look forward your reply
    hakan
    Attachments:
    error8.JPG ‏8 KB

  • I am moving to Alice Springs, Australia, this summer from the U.S. I would like to get the new iPad. How can I found out if I will be able to access all the functionality in Alice? Will I need to purchase a local plan of some sort?

    I am moving to Alice Springs, Australia, this summer from the U.S. I would like to get the new iPad to use while traveling back and forth from the U.S. to Australia, and within Australia. How can I found out if I will be able to access all the functionality of the iPad in Alice? Will I need to purchase a local plan of some sort? I have never owned an Apple product before -- I'm a newby!

    Aside form the limitation of LTE to the 700MHz and 2.1GHz bands (which rules out LTE in Europe I gather, at least as it stands now) the new iPad should let you use a GSM 3g/2g/edge network anywhere.  The CDMA Verizon model will only be able to use it's native CDMA radio band in the USA (that radio will be locked to Verizon), but it's international GSM radio is the same as the AT&T model.
    Keep in mind though that by far the cheapest option when abroad is to take advantage of free wifi as much as possible (well, that is always the cheapest option, since it is free).  I know several people who have taken their wifi-only iPads and iPad2s to Europe and said they did not find the lack of 3G really inconvenient at all as most towns had plenty of free or cheap wifi access all over the place.
    And in 3 years, your iPad will be at least 2-3 generations behind, LTE will have already been replaced by 5G or whatever the next new generation of cellular ends up being named (and the "young" kids will be wondering what the heck 3G even means or meant - dang that stuff was from the olden days!), and you can pitch that ancient piece of technology and start things all over again 

  • I have two iPhones on my iTunes account. How can I find out what apps go to which phone?

    I have two iPhones on my iTunes account. How can I find out what apps go to which phone?

    I don't believe that there is a way to do that.  I would sugest using automatic downloads to keep your apps synced across both phones.  You might also want to note that just about any app you have ever download will be available for free download via icloud.
    Wish I could be more help.

Maybe you are looking for

  • Making fields required based on other field input

    I am creating a form in adobe acrobat pro that employees need to fill in to show the clients they have worked for in a week. The form has 10 lines for them to fill in the date, client name, address etc for 10 clients. I want to make the client name a

  • Use of common distribution channel and division in CRM

    Hi, I have a requirement where the customer master will be created in a single dist channel and division combination in ECC and downloaded to CRM. However this customer will be used in different sales area combinations in CRM and ECC. In ECC there is

  • Performa 6300CD - Which Monitor Adapter?

    A friend has a Mac Performa 6300CD with the stock Apple monitor that came with it. The monitor is starting to go, and he wants to connect a generic monitor. Does anyone know what type of adapter he would need? Thanks.

  • I see * in some of rows in web report ?

    Hello all, When i am running some of my reports in web I see only * in some cells and when I export it to excel i can see the actual value. Is there any setting that i need to do do for web. ? The two rows that are not showing up properly and showing

  • Black side bars--NOT widescreen

    I know I've read about this a long time ago but have since forgotten it and I can't seem to dig up the answer in the archives so I ask for patience. I just made a long-term loan of my now-unused Canon GL 1 to a friend who is doing some extensive vide