Java Video Tutorial 29

[ad_1]
Get the Code:

In this part of the Java Video Tutorial series, I cover GridLayout, GridBagLayout, GridBagConstraints, Font, Insets and much more.

I do this by showing you how to create a calculator layout with Java Swing. You’ll see just how easy it is to layout a nice GUI interface using constraints. You don’t necessarily need to measure X and Y coordinates to get everything to look right.


Posted

in

by

Tags:

Comments

30 responses to “Java Video Tutorial 29”

  1. Hà Chí Hào Avatar

    You set the grid 0 rows and 3 columns but why when complie it show 4×3 grid ???

  2. TheSelfishME Avatar

    Set the width of textResult to 8 and everything will be in proportion no matter what size the frame is, i.e.,

    textResult = new JTextField("0", 8);


    gridConstraint.gridwidth = 8;
    gridConstraint.gridx = 5;
    thePanel.add(textResult, gridConstraint);

  3. Computer Science Avatar

    Who asks for homework ??? lol . Most of us are here because of H/W. haha. Great video, once again.

  4. Pamela Lohia Avatar

    For those having problems with button sizes, i.e. 1, 4 and 7 smaller than the rest, setting this.setSize to (350,580) fixed it for me.

  5. Andrew Muller Avatar

    Super proud of my calculator and thought viewers might appreciate it. Took me ages to work out the kinks but I think it's bug free now (fingers crossed!). Have also made it so that you can either use the keyboard numbers and operators or the JButtons, or a combination of both. The code to copy and paste into Eclipse is here: http://pastebin.com/LWqV7ABP

  6. Nickolay Pelov Avatar

    I'm having hard time to get used to layouts. What would have helped is if you add components one by one and run to show what difference it makes.

  7. no hEal Avatar

    awesome, thanks for the vid. You're better than the professor we pay for in university. We actually sit for 3 hours to learn this and you did it only for 10 mins.

  8. Ahmad Sedeek Avatar

    Thank you Derek am learning java with you till now and made this to a full functional Calculator and added more buttons but am still stuck at exceptions for this but i will figure it out
    Thank you very much 🙂

  9. HezyFoShizy Avatar

    Can I put my BoxLayouts in a JPanel and then add the panel to my GridBagLayout?
    I'm trying to do this and its going all over the place when I compile it.

  10. Peteman12 Avatar

    When I did this, the leftmost buttons would be by default squashed compared to the others. When I stretched the window, it evened out, but do you know why it might do that?

  11. Sagar Nayak Avatar

    hello
    i have subscribed to your channel but yesterday it was automatically unsubscribed . can you tell me why ?

    thanks

  12. Ali Amid Avatar

    Why did you have the values 1,5, and 9 at gridx? Couldnt you use 1,2,and 3?

  13. Красимир Райков Avatar

    Hello there. I found your videos very useful and I appreciate your effort.
    I'm currently trying to make my Calculator work. I found a problem with which I've been struggling all day. Can I ask you for some help? Here is part of the source code. http://pastebin.com/111dFpeW
    If the user enter a number which first digit is zero, to be not able to enter another zero. (For example 00 or 000 and so on)
    Thanks in advance!

  14. BoogieBass22 Avatar

    Which video do you do the panels inside panels?

  15. Krishan Koenig Avatar

    is there any possibility to make the code in the ListenForButton Class more efficient (less code)?
    http://pastebin.com/YFSf2ncD

  16. TheRoxas13th Avatar

    I'm still don't understand how the GridBagLayout work, especially the weight and and anchor method. Any one care to explain it?

  17. alkolaqi83 Avatar

    i hate using java layout manager  I discover MiG Layout because its way easier and nicer to implement. I really hope java team work to implement a better layout manager. As always thanks for this great videos it helps a lot

  18. Jack Daniels Avatar

    Is there any disadvantage/advantage to using super("title"); vs setTitle("title"); Other than being able to change the title while the program is running.

  19. T Catalin Avatar

    Derek, when is ok to learn about Design Patterns, OOD, java algorithms ? After I learn all the videos here in Java ?

  20. Kaelen Doughty Avatar

    Hi Derek, I'm eternally grateful for your tutorial videos, without them I would be lost. I am attempting to do the homework for this video and am running into several issues. If you or anyone else could post the code for the solution I would really appreciate it. Specifically how to return the values back into the textResult TextField. Thank you again for the work you do.

  21. Derek Banas Avatar

    Yes the GridBag has its positives and negatives for all of that ease of use. That is why I tend not to use it most of the time

  22. mausyxl Avatar

    For some reason the buttons on the left (C,1,4,7) are twice as small as the other buttons.
    Even if i copy-paste your code it doesnt work out. I think it has to do with:

    gridConstraints.fill = GridBagConstraints.BOTH;

    If i remove that line everything is the same size, but then the screen is not filled anymore. (surprise)

    I use windows.

    Thanks.

  23. Derek Banas Avatar

    Yes that is pretty much true. There are also gui editors for Eclipse. I just like to teach everything in case people need to go into the code and tinker with it.

  24. Zohaib ul hassan Avatar

    Hi Derek its definitely plus point to know all the coding for the layout but I heard we can do all that in Netbeans graphically is it true?

  25. Derek Banas Avatar

    They give the layout manager a hint on how to adjust weight

  26. Chann Dara keo Avatar

    What is weightx, weighty?

  27. Derek Banas Avatar

    It is just a matter of using event handlers. I cover them in detail in the tutorial. Tell me if you need help finding the right videos

  28. Alec Hewitt Avatar

    Okay, ummm…. one problem. I don't know how to turn that into a working calculator :

  29. Derek Banas Avatar

    I do my best to reply to every comment. I probably get 95% of them. It isn't that hard because I have answered questions on programming forever. Sometimes I forget about code I wrote years ago though 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *