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());
}
}
}
On this page of the site you can watch the video online Java combobox 📑 with a duration of hours minute second in good quality, which was uploaded by the user Bro Code 25 August 2020, share the link with friends and acquaintances, this video has already been watched 98,978 times on youtube and it was liked by 2.1 thousand viewers. Enjoy your viewing!