tubeshowcase●1,354,442 videos♡ My collection 0
← Learn to Code

Learn to Code10:30

Java combobox 📑

Bro Code ↗

From the creator

Java, combobox, JComboBox, GUI, swing, tutorial, beginners, #Java #combobox #JComboBox #GUI #swing #tutorial #beginners //*********************************************** 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()); } } }

Published 2020-08-25 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code