Java BorderLayout 🧭

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024

ความคิดเห็น • 94

  • @BroCodez
    @BroCodez  4 ปีที่แล้ว +67

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    public class Main{
    public static void main(String[] args) {
    // Layout Manager = Defines the natural layout for components within a container

    // 3 common managers

    // BorderLayout = A BorderLayout places components in five areas: NORTH,SOUTH,WEST,EAST,CENTER.
    // All extra space is placed in the center area.
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    frame.setLayout(new BorderLayout(10,10));
    frame.setVisible(true);
    JPanel panel1 = new JPanel();
    JPanel panel2 = new JPanel();
    JPanel panel3 = new JPanel();
    JPanel panel4 = new JPanel();
    JPanel panel5 = new JPanel();

    panel1.setBackground(Color.red);
    panel2.setBackground(Color.green);
    panel3.setBackground(Color.yellow);
    panel4.setBackground(Color.magenta);
    panel5.setBackground(Color.blue);

    panel5.setLayout(new BorderLayout());

    panel1.setPreferredSize(new Dimension(100,100));
    panel2.setPreferredSize(new Dimension(150,100));
    panel3.setPreferredSize(new Dimension(150,100));
    panel4.setPreferredSize(new Dimension(100,100));
    panel5.setPreferredSize(new Dimension(100,100));

    //------------- sub panels --------------------

    JPanel panel6 = new JPanel();
    JPanel panel7 = new JPanel();
    JPanel panel8 = new JPanel();
    JPanel panel9 = new JPanel();
    JPanel panel10 = new JPanel();

    panel6.setBackground(Color.black);
    panel7.setBackground(Color.darkGray);
    panel8.setBackground(Color.gray);
    panel9.setBackground(Color.lightGray);
    panel10.setBackground(Color.white);

    panel5.setLayout(new BorderLayout());

    panel6.setPreferredSize(new Dimension(50,50));
    panel7.setPreferredSize(new Dimension(50,50));
    panel8.setPreferredSize(new Dimension(50,50));
    panel9.setPreferredSize(new Dimension(50,50));
    panel10.setPreferredSize(new Dimension(50,50));

    panel5.add(panel6,BorderLayout.NORTH);
    panel5.add(panel7,BorderLayout.SOUTH);
    panel5.add(panel8,BorderLayout.WEST);
    panel5.add(panel9,BorderLayout.EAST);
    panel5.add(panel10,BorderLayout.CENTER);

    //------------- sub panels --------------------

    frame.add(panel1,BorderLayout.NORTH);
    frame.add(panel2,BorderLayout.WEST);
    frame.add(panel3,BorderLayout.EAST);
    frame.add(panel4,BorderLayout.SOUTH);
    frame.add(panel5,BorderLayout.CENTER);
    }
    }

    • @carmellibre6324
      @carmellibre6324 3 ปีที่แล้ว

      What app did you use for this code?

    • @cate01a
      @cate01a 3 ปีที่แล้ว

      @@carmellibre6324 eclipse, and he ran it just using windows cmd I suppose; you can code in a .txt and run it use cmd, and you can code in stuff like textpad and sublime text

    • @dulcemaria4688
      @dulcemaria4688 2 ปีที่แล้ว

      This is the lesson and the right teacher I've been looking for all this time. Thanks..

    • @ravimakwana992
      @ravimakwana992 2 ปีที่แล้ว

      thank you

    • @Gianni.93
      @Gianni.93 9 หลายเดือนก่อน

      why panel5.setLayout(new BorderLayout());
      is present twice?

  • @ShrihariNBhat
    @ShrihariNBhat 3 ปีที่แล้ว +7

    Lucky that I found your channel 10/10 for mic quality and content

  • @oguzhankantarc7301
    @oguzhankantarc7301 4 ปีที่แล้ว +12

    Im supporting my main training in Java with your vids. Awesome courses, i love the way of your explaining things. Keep it up bro =)

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +2

      Awesome, thank you!

  • @markpaycol3670
    @markpaycol3670 3 ปีที่แล้ว +5

    Hi, you really help me to understand borders. Spending half of my day understanding this without any help and I finally found this. Great work!

  • @deepeshsingh7717
    @deepeshsingh7717 4 ปีที่แล้ว +7

    Glad I found your channel as a amateur, still learning Java programmer.

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 ปีที่แล้ว +2

    This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro

    • @josesamuel7615
      @josesamuel7615 ปีที่แล้ว

      i'm from Brazil and do the same

  • @rolakhaled5070
    @rolakhaled5070 8 หลายเดือนก่อน +1

    brocode you always save me in every single new programming concept i want to learn you are very amazing

  • @dianamilenaarchilacordoba4632
    @dianamilenaarchilacordoba4632 2 หลายเดือนก่อน

    great video!!! I'm infinitely grateful for your dedication and big heart to share this knowledge with the world. Thank you soo much

  • @parindyapigera1790
    @parindyapigera1790 ปีที่แล้ว

    Thanks man...I don't know how to say this but I've solved a huge problem because of you...

  • @elvispontes4165
    @elvispontes4165 2 ปีที่แล้ว

    Hey Bro... you are the best... never stop doing this awesome job : D

  • @qaisayyash8116
    @qaisayyash8116 2 ปีที่แล้ว

    I love the way of your explaining things.And you help me a lot.
    Thx u bro
    Keep it up bro

  • @chriscentproductions
    @chriscentproductions ปีที่แล้ว

    Can you also make a tutorial about Java BoxLayout?
    It seems after surfing the web, yours is the only cleanest and the most understandable code I can read.

  • @monwil3296
    @monwil3296 4 ปีที่แล้ว +3

    👌, I bet tomorrow we're animating them 🙏

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +3

      I have no idea what we're doing tomorrow lol

  • @blabberq
    @blabberq 3 ปีที่แล้ว

    Glad I found your channel, great tutorial :)

  • @abdusselamspahiu2151
    @abdusselamspahiu2151 ปีที่แล้ว

    very nice learning clips

  • @elod2405
    @elod2405 2 ปีที่แล้ว

    Hey, love your video, it's very good for my learning. thank you so much :)

  • @Simis999
    @Simis999 2 ปีที่แล้ว

    Kaip visada įdedi daug darbo ir gerai paaiškini

  • @kaushalprasadyadav9242
    @kaushalprasadyadav9242 2 ปีที่แล้ว

    Great work bro. Please make videos for mobile app development....

  • @07GT783
    @07GT783 ปีที่แล้ว

    great explanation.

  • @programmer5834
    @programmer5834 2 ปีที่แล้ว

    Thanks boss for you all episode 😊

  • @ikatuviajes
    @ikatuviajes ปีที่แล้ว

    Great Video! thanks!!

  • @chicogomu4382
    @chicogomu4382 9 หลายเดือนก่อน

    Gracias! Me sirvió mucho su video :)

  • @danny.3036
    @danny.3036 3 ปีที่แล้ว

    Thanks, Bro! ☕ You're awesome!

  • @sabermmirza
    @sabermmirza 4 ปีที่แล้ว +1

    thanks for share

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว

      Thanks for watching Saber!

  • @kemann3815
    @kemann3815 3 ปีที่แล้ว

    Another great tutorial

  • @alexshepel5599
    @alexshepel5599 4 ปีที่แล้ว +1

    Nice, bro.

  • @henriquefelinimena3693
    @henriquefelinimena3693 3 ปีที่แล้ว

    Thank you for the content!

  • @marioshusband3700
    @marioshusband3700 4 ปีที่แล้ว +3

    Early gang where you at

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +2

      It's just you Donkey lol
      **cries**

  • @Amirrjl-y8z
    @Amirrjl-y8z 11 หลายเดือนก่อน

    Amazing

  • @hudasameh51
    @hudasameh51 ปีที่แล้ว

    Hey bro thanks very much ..🥰🥰

  • @EdgeLordOmen
    @EdgeLordOmen 7 หลายเดือนก่อน

    Nice

  • @reptileita
    @reptileita 2 ปีที่แล้ว

    There are no words to express how awesome these videos are!

  • @mohamedeljaouhari2073
    @mohamedeljaouhari2073 2 ปีที่แล้ว

    Thank you !

  • @juandavidcubillos6909
    @juandavidcubillos6909 3 ปีที่แล้ว

    thank you it was a great help

  • @tmro5356
    @tmro5356 2 ปีที่แล้ว

    Thank you Bro!

  • @KeithFowler-v4d
    @KeithFowler-v4d ปีที่แล้ว

    awsome !!!

  • @augischadiegils.5109
    @augischadiegils.5109 4 ปีที่แล้ว +1

    Thankss bro :)

  • @EdgeLordOmen
    @EdgeLordOmen 7 หลายเดือนก่อน

    Brocode when will you make a java that's connected to database

  • @ctluwua7695
    @ctluwua7695 3 ปีที่แล้ว

    YOU always rock

  • @wassimkhedir6977
    @wassimkhedir6977 3 ปีที่แล้ว

    Thank You So Much Bro

  • @preciousmatos
    @preciousmatos 3 ปีที่แล้ว +3

    Thank you very much for the 12hr tutorial. I am having a issue with panel 6-10 . The north south east west cernter doesn't seem to be working. I did panel5.add(panel6, BorderLayout.NORTH).... Can you tell me why🤔

    • @elvispontes4165
      @elvispontes4165 2 ปีที่แล้ว

      I tried it this way... se if it works for you...
      import javax.swing.*;
      import java.awt.*;
      public class MyFrame extends JFrame {
      JPanel panel1;
      JPanel panel2;
      JPanel panel3;
      JPanel panel4;
      JPanel panel5;
      JPanel panel11;
      JPanel panel22;
      JPanel panel33;
      JPanel panel44;
      JPanel panel55;
      JPanel panel111;
      JPanel panel222;
      JPanel panel333;
      JPanel panel444;
      JPanel panel555;
      ImageIcon icon = new ImageIcon("mushroom.png");
      MyFrame(){
      this.setIconImage(icon.getImage());
      this.setTitle("Mushroom TextEditor");
      this.setSize(900,750);
      this.setDefaultCloseOperation(MyFrame.EXIT_ON_CLOSE);
      this.setLayout(new BorderLayout(5,5));
      this.setVisible(true);
      panel1 = new JPanel();
      panel2 = new JPanel();
      panel3 = new JPanel();
      panel4 = new JPanel();
      panel5 = new JPanel();
      panel1.setBackground(Color.blue);
      panel2.setBackground(Color.MAGENTA);
      panel3.setBackground(Color.red);
      panel4.setBackground(Color.GREEN);
      panel5.setBackground(Color.white);
      panel1.setPreferredSize(new Dimension(25, 25));
      panel2.setPreferredSize(new Dimension(25, 25));
      panel3.setPreferredSize(new Dimension(25, 25));
      panel4.setPreferredSize(new Dimension(25, 25));
      panel5.setPreferredSize(new Dimension(25, 25));
      panel5.setLayout(new BorderLayout(5,5));
      this.add(panel1, BorderLayout.NORTH);
      this.add(panel2, BorderLayout.EAST);
      this.add(panel3, BorderLayout.WEST);
      this.add(panel4, BorderLayout.SOUTH);
      this.add(panel5, BorderLayout.CENTER);
      //====================================================
      panel11 = new JPanel();
      panel22 = new JPanel();
      panel33 = new JPanel();
      panel44 = new JPanel();
      panel55 = new JPanel();
      panel11.setBackground(Color.pink);
      panel22.setBackground(Color.darkGray);
      panel33.setBackground(Color.yellow);
      panel44.setBackground(Color.CYAN);
      panel55.setBackground(Color.white);
      panel11.setPreferredSize(new Dimension(25, 25));
      panel22.setPreferredSize(new Dimension(25, 25));
      panel33.setPreferredSize(new Dimension(25, 25));
      panel44.setPreferredSize(new Dimension(25, 25));
      panel55.setPreferredSize(new Dimension(25, 25));
      panel55.setLayout(new BorderLayout(5,5));
      panel5.add(panel11, BorderLayout.NORTH);
      panel5.add(panel22, BorderLayout.EAST);
      panel5.add(panel33, BorderLayout.WEST);
      panel5.add(panel44, BorderLayout.SOUTH);
      panel5.add(panel55, BorderLayout.CENTER);
      //=========================================================
      panel111 = new JPanel();
      panel222 = new JPanel();
      panel333 = new JPanel();
      panel444 = new JPanel();
      panel555 = new JPanel();
      panel111.setBackground(Color.green);
      panel222.setBackground(Color.blue);
      panel333.setBackground(Color.MAGENTA);
      panel444.setBackground(Color.red);
      panel555.setBackground(Color.white);
      panel111.setPreferredSize(new Dimension(25, 25));
      panel222.setPreferredSize(new Dimension(25, 25));
      panel333.setPreferredSize(new Dimension(25, 25));
      panel444.setPreferredSize(new Dimension(25, 25));
      panel555.setPreferredSize(new Dimension(25, 25));
      panel55.add(panel111, BorderLayout.NORTH);
      panel55.add(panel222, BorderLayout.EAST);
      panel55.add(panel333, BorderLayout.WEST);
      panel55.add(panel444, BorderLayout.SOUTH);
      panel55.add(panel555, BorderLayout.CENTER);
      }
      public static void main(String[]args){
      new MyFrame();
      }
      }

  • @traveltheworld5241
    @traveltheworld5241 ปีที่แล้ว

    //Shy of 7 hours in,can't wait to have a breeze next semester...

  • @siriusleto3758
    @siriusleto3758 2 ปีที่แล้ว

    Thanks.

  • @nawfalnjm5699
    @nawfalnjm5699 3 ปีที่แล้ว

    thank you so much !

  • @snailcat8767
    @snailcat8767 3 ปีที่แล้ว

    Thank you so much

  • @nidhiprasad9732
    @nidhiprasad9732 3 ปีที่แล้ว

    Thank you

  • @MrLoser-ks2xn
    @MrLoser-ks2xn 2 ปีที่แล้ว

    Thanks

  • @sairos4057
    @sairos4057 ปีที่แล้ว

    thaaaaaaaanks bro

  • @ASIFAlI-lq4rd
    @ASIFAlI-lq4rd 3 ปีที่แล้ว

    great

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 ปีที่แล้ว

    thanks bro

  • @LYJManchesterUnited
    @LYJManchesterUnited 4 หลายเดือนก่อน

    Hi people do you know how to make the center small and hence the south bigger? Ty!

  • @svalyavasvalyava9867
    @svalyavasvalyava9867 3 ปีที่แล้ว

    thanks a lot!

  • @feitan5474
    @feitan5474 2 ปีที่แล้ว

    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    The method setLayout(LayoutManager) in the type JFrame is not applicable for the arguments (BorderLayout)
    NORTH cannot be resolved or is not a field

  • @GtExtra-gb4ue
    @GtExtra-gb4ue ปีที่แล้ว

    I have an error when adding an frame.setLayout(new BorderLayout()); the set layout will in red underline

  • @atharvat2463
    @atharvat2463 2 ปีที่แล้ว +1

    import java.awt.BorderLayout is not working

  • @BadBoyRaduCs
    @BadBoyRaduCs ปีที่แล้ว

    HI Bro. How can i add a action listener to change the colors betwin them ? my code is still glitchy and i cant make it work.

  • @joyceasante8292
    @joyceasante8292 ปีที่แล้ว

    My code
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class Main{
    public static void main(String[ ] args){
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500, 500);
    frame.setLayout(new BorderLayout(10, 0));
    frame.setVisible(true);

    JPanel panel1 = new JPanel( );
    JPanel panel2 = new JPanel( );
    JPanel panel3 = new JPanel( );
    JPanel panel4 = new JPanel( );
    JPanel panel5 = new JPanel( );
    panel1.setBackground(Color.orange);
    panel2.setBackground(Color.blue);
    panel3.setBackground(Color.pink);
    panel4.setBackground(Color.green);
    panel5.setBackground(Color.yellow);
    panel1.setPreferredSize(new Dimension(50,50));
    panel2.setPreferredSize(new Dimension(50,50));
    panel3.setPreferredSize(new Dimension(50,50));
    panel4.setPreferredSize(new Dimension(50,50));
    panel5.setPreferredSize(new Dimension(50,50));
    frame.add(panel1, BorderLayout.SOUTH);
    frame.add(panel1, BorderLayout.EAST);
    frame.add(panel1, BorderLayout.WEST);
    frame.add(panel1, BorderLayout.NORTH);
    frame.add(panel1, BorderLayout.CENTER);
    //*****sub-panels*********
    JPanel panel6 = new JPanel( );
    JPanel panel7 = new JPanel( );
    JPanel panel8 = new JPanel( );
    JPanel panel9 = new JPanel( );
    JPanel panel10 = new JPanel( );
    panel6.setBackground(Color.black);
    panel7.setBackground(Color.darkGray);
    panel8.setBackground(Color.gray);
    panel9.setBackground(Color.lightGray);
    panel10.setBackground(Color.white);
    panel5.setLayout(new BorderLayout());
    panel6.setPreferredSize(new Dimension(50,50));
    panel7.setPreferredSize(new Dimension(50,50));
    panel8.setPreferredSize(new Dimension(50,50));
    panel9.setPreferredSize(new Dimension(50,50));
    panel10.setPreferredSize(new Dimension(50,50));
    panel5.add(panel6,BorderLayout.SOUTH);
    panel5.add(panel7,BorderLayout.NORTH);
    panel5.add(panel8,BorderLayout.EAST);
    panel5.add(panel9,BorderLayout.WEST);
    panel5.add(panel10,BorderLayout.CENTER);
    //*****sub-panels****
    frame.add(panel1,BorderLayout.SOUTH);
    frame.add(panel2,BorderLayout.EAST);
    frame.add(panel3,BorderLayout.WEST);
    frame.add(panel4,BorderLayout.NORTH);
    frame.add(panel5,BorderLayout.CENTER);
    }
    }

  • @protomonke
    @protomonke 2 ปีที่แล้ว

    👍🏻

  • @danialsharifi3513
    @danialsharifi3513 2 ปีที่แล้ว

    How we can add panels like a flag?

  • @ogrroyalty5875
    @ogrroyalty5875 2 ปีที่แล้ว

    for example i got two classes, Rightpanel and Leftpanel. both have a Jpanel inside. how do i both add them to antoher class in a jframe?

  • @carmellibre6324
    @carmellibre6324 3 ปีที่แล้ว

    what app did you use for this code

  • @greeneggsandmushrooms9855
    @greeneggsandmushrooms9855 3 ปีที่แล้ว

    cross the border layout

  • @brandonjablasone7544
    @brandonjablasone7544 2 ปีที่แล้ว

    Can I add text to each of the border that was created

  • @augischadiegils.5109
    @augischadiegils.5109 3 ปีที่แล้ว

  • @coltonbailey8873
    @coltonbailey8873 3 ปีที่แล้ว

    Does the format of the way I code matter? Is it better to structure code like
    set1/set2/set3 set1/set1/set1
    set1/set2/set3 vs set2/set2/set2
    set1/set2/set3 set3/set3/set3
    panel1.setBackground(); panel1.setBackground();
    panel2.setBackground(); vs panel1.setPreferredSize();
    panel3.setBackground(); panel1.setLayout();
    I know they both do the same thing in the end, but is 1 logic better than the other? If so why? I personally think option 1 is easier to setup, but maybe option 2 if the program is extremely custom? Help @_@

    • @coltonbailey8873
      @coltonbailey8873 3 ปีที่แล้ว

      These layout videos got me wondering if the layout of the way I code, is set to null X.X

  • @ValeriaGarciaHernandez
    @ValeriaGarciaHernandez 2 ปีที่แล้ว

    Hi, I had wrote the code, but when I write frame.setLayout(new BorderLayout()); setLayout appears in red and says The method setLayout(LayoutManager) in the type JFrame is not applicable for the arguments (BorderLayout)
    If anyone knows how to fix this and get the code working, thanks 👍

    • @A_Ched
      @A_Ched ปีที่แล้ว

      You may have set the class name to BorderLayout. That is probably why its not working. If you're still wondering lol.

  • @sujayirrinki4915
    @sujayirrinki4915 10 หลายเดือนก่อน

    for the algo

  • @zari_723
    @zari_723 2 ปีที่แล้ว

    i dont really see the point of this but i just wanted to let you know ~ Bro xDD

  • @antoinealam6531
    @antoinealam6531 2 หลายเดือนก่อน

    bro

  • @lorenzschwarz5877
    @lorenzschwarz5877 3 ปีที่แล้ว

    +

  • @wombozombo
    @wombozombo 10 หลายเดือนก่อน

    comment

  • @khalidmuzemil9020
    @khalidmuzemil9020 6 หลายเดือนก่อน

    bro code

  • @garyvarkey9546
    @garyvarkey9546 3 ปีที่แล้ว

    .

  • @eugenezuev7349
    @eugenezuev7349 6 หลายเดือนก่อน

  • @ravimakwana992
    @ravimakwana992 2 ปีที่แล้ว

    Thank You so much!

  • @karlardeno4111
    @karlardeno4111 ปีที่แล้ว

    Thanks bro