Java combobox 📑

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

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

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

    //***********************************************
    public class Main{
    public static void main(String[] args) {

    // JComboBox = A component that combines a button or editable field and a drop-down list

    new MyFrame();
    }
    }
    //***********************************************
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MyFrame extends JFrame implements ActionListener{
    JComboBox comboBox;

    MyFrame(){
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new FlowLayout());

    String[] animals = {"dog","cat","bird"};

    comboBox = new JComboBox(animals);
    comboBox.addActionListener(this);

    //comboBox.setEditable(true);
    //System.out.println(comboBox.getItemCount());
    //comboBox.addItem("horse");
    //comboBox.insertItemAt("pig", 0);
    //comboBox.setSelectedIndex(0);
    //comboBox.removeItem("cat");
    //comboBox.removeItemAt(0);
    //comboBox.removeAllItems();

    this.add(comboBox);
    this.pack();
    this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
    if(e.getSource()==comboBox) {
    System.out.println(comboBox.getSelectedItem());
    //System.out.println(comboBox.getSelectedIndex());
    }
    }
    }

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

    Hey Bro, I'm from Brazil and I want to thank you for all your videos about java. I have been learning a lot with BroCode channel. Thank you!

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

    Danke schon bruder. Your explanation was straight to the point and clear. Also thanks for the code.

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

    420th like 😎
    your videos really help bro! Thank you!

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

    Doing my Part to defeat the Algorithm.
    Keep it up mate!!!

  • @K-tf5ph
    @K-tf5ph 4 ปีที่แล้ว +9

    Very clean explanation. It was really helpful for me, thanks ✓

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

      thank you for watching Kaymak!

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

    I love your gui vidios they are so helpful

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

      thank you Nono!

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

    i have become a good developer in java because your video are extra ordinaire, very claire:
    thantyou bro, God bless you a lot

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

    coooooool , best tutorials ever , good job bro code

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

    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

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

    Thank you for all your work

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

    Subscribed. Please do more tut of Gui in java

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

      thanks bro! I will

  • @OmerFaruk-pu6cd
    @OmerFaruk-pu6cd 4 ปีที่แล้ว +4

    you saved my day tnx

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

    Thank you very much for this video
    very clear!

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

    this is what I call quality content

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

    You are the best!! :)

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

    please do tutorial of jdbc also and make a project using Java Swing and JDBC

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

    Great

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

    Thanks brother 😊

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

    Great video, thanks

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

    This was verry helpfull

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

    Very good.

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

    ty

  • @MuhammadAwais-g7f
    @MuhammadAwais-g7f 5 หลายเดือนก่อน

    Thanks bro

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

    thank you for the content

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

    Nice, bro!

  • @Cooleditorno.1
    @Cooleditorno.1 11 หลายเดือนก่อน

    Thanks

  • @Amangupta-rh7cy
    @Amangupta-rh7cy 3 ปีที่แล้ว +2

    Good video

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

    Love this.

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

    Thank you very much for sharing this video, easy to understand.

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

    Thanks that was helpful 👍

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

    NIce video

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

    thanks bro

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

    thx
    Ur the best

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

    gooood job

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

    keep it on

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

    Da best

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

    combobox. yeah

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

    hi, have a great Sunday

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

    how much do you program every day?

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

      I mostly code exclusively for these videos almost daily, but I do have other projects I work on occasionally

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

    Oh never mind never mind I got it. For the actionPerformed method, you would then continue it with numerous if statements and say "if(animals.getSelectedIndex()==0 {sysout("German Sheppard")" i see now, i get it

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

      You should’ve replied this to your original comment lol

  • @PMe-my1td
    @PMe-my1td 3 ปีที่แล้ว

    Hey Bro! Question for you!
    How do you setSelectedItem(String_var_here) from another class calling the JcomboBox. It doesnt show the change on the GUI and the box is 'frozen'.

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

    How to store user’s selection in a variable

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

    how can I sort alphabetically items inside a combobox ? Thanks

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

    wombo combo

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

    Can i change the color of scroll? How?

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

    hello

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

    4:25 so what if you want the getSelectedItem to show different text that corresponds to each string on the GUI? So let's say I want to click dog and I want the sysout to say "German Sheppard", how you do that?
    Thanks for the reply and your free educational videos

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

      If statement, in the action listener, if the text is dog, output German shepard

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

      @@AnthonyR007 so i did exactly that but now i have hundreds of if statements for every single dog breed and it looks totally all unprofessional and not "programmer like". I'm trying to make an array of dog breeds and just writing one if statements with the array number in the parameters

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

      @@AnthonyR007 i can't quite get it to work because I'm not trained or a professional so i guess I'll just continue writing hundreds of if statements like a noob lol

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

      @@jaybartgis5148 you could use a switch case statement with the indexes?

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

      It’ll still be a lot of code, but it will be less resource intensive

  • @3r3h17
    @3r3h17 2 ปีที่แล้ว

    Can I add a JComboBox on a JFrame with null Layout or a BorderLayout?

    • @Michel-dx1bn
      @Michel-dx1bn 2 ปีที่แล้ว +1

      Yes, in this video he used a border layout ( If you don't set a layout for a JFrame, it will use a BorderLayout by default )
      Also it works for null layout but don't forget to set the bounds and pack the frame.

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

    Oh. So this isn’t minecraft

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

    Hi, guys. Can someone help me with one situation I noticed? When I use the setEditable method and type one item that isn't the first one it executes the action performed method twice. This doesn't happen when I type in the comboBox the first Item.
    I'm goin' to let the code here in case anyone knows what is wrong here, and how can I make it work better.

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

      import java.awt.FlowLayout;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import javax.swing.JComboBox;
      import javax.swing.JFrame;
      public class Main {
      public static void main (String [] args) {
      new MyFrame();
      }
      }
      class MyFrame extends JFrame implements ActionListener {
      JComboBox comboBox;
      MyFrame() {
      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      this.setLayout(new FlowLayout());
      String [] animals = {"dog","cat","bird"};
      comboBox = new JComboBox(animals);
      comboBox.addActionListener(this);
      comboBox.setEditable(true);
      this.add(comboBox);
      this.pack();
      this.setVisible(true);
      }
      @Override
      public void actionPerformed(ActionEvent e) {
      if (e.getSource() == comboBox) {
      System.out.println(comboBox.getSelectedItem());
      System.out.println(comboBox.getSelectedIndex());
      }
      }
      }

  • @HousseinDroubi-o9i
    @HousseinDroubi-o9i 4 หลายเดือนก่อน

    Hey.

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

    Comment

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

    🐽🐕🐈

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

    Yo just wanna say that GOD loved the world so much he sent his only begotten
    son Jesus to die a brutal death for us so that we can have eternal life
    and we can all accept this amazing gift this by simply believing in him (Jesus) asking for the forgiveness of your sins
    and forming a relationship with heavenly father.

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

    Practicing...
    public class Main{
    public static void main(String[]args){
    new MyFrame();
    }
    }
    *****************************
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MyFrame extends JFrame implements ActionListener{
    JComboBox comboBox;

    MyFrame(){
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new FlowLayout());
    String[]destinations = {"Zanzibar","Solomon Islands", "Saint Lucia"};
    //Integer[]destinations = {1,2,3};
    comboBox = new JComboBox();
    comboBox.addActionListener(this);
    //comboBox.setEditable(true);
    //System.out.println(comboBox.getItemCount());
    //comboBox.add("Senegal");
    //comboBox.insertItemAt("Turks and Caicos Islands",3);
    //comboBox.setSelectedIndex(3);
    //comboBox.removeItem("Saint Lucia");
    //comboBox.removeItemAt(0);
    comboBox.removeAllItems();

    this.add(comboBox);
    this.pack();
    this.setVisible(true);
    }
    @Override
    public void actionPerformed(ActionEvent e){
    if(e.getSource()==comboBox){
    //System.out.println(comboBox.getSelectedItem());
    System.out.println(comboBox.getSelectedIndex());
    }
    }
    }

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

    Thanks