JList adalah komponen yang digunakan untuk
menyajikan kotak pilihan, dengan terdapat pada kotak pilihan, Jumlah pilihan
akan nampak sesuai dengan ukuran jendela, jika pilihanya lebih banyak maka
jendela akan menggulung dengan menekan scroll bar.
berikut contoh sintaknya :
import javax.swing.*;
import java.awt.*;
class list extends JFrame {
list(String title) {
setTitle(title);
setLocation(300, 100);
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel igna = new JPanel();
JPanel igna1 = new JPanel();
JPanel igna2 = new JPanel();
JButton B1 = new JButton("BACK");
JButton B2 = new JButton("NEXT");
JLabel lab = new JLabel("SILAKAN PILIH BUAH FAVORIT MU");
JList made = new JList(new String[] { "Apel", "Mangga", "Anggur",
"Alpokat", "Jeruk", "Pisang", "Strawbery", "Nanas", "Nangka",
"Kedondong", "Pepaya" });
igna.setBackground(Color.gray);
igna.add(lab);
igna.add(made);
lab.setFont(new Font("Arial", Font.BOLD, 11));
made.setFont(new Font("Vijaya", Font.BOLD, 14));
lab.setForeground(Color.yellow);
made.setBackground(Color.green);
made.setForeground(Color.red);
igna.setLayout(new GridLayout(1, 1));
add(igna);
add(igna, BorderLayout.NORTH);
igna1.add(B1);
igna1.add(B2);
add(igna1);
igna1.setBackground(Color.black);
add(igna1, BorderLayout.SOUTH);
add(igna2);
igna2.setBackground(Color.pink);
add(igna2, BorderLayout.CENTER);
setVisible(true);
}
public static void main(String args[]) {
list IGNA = new list("Ignatius JList Program");
}
}
import java.awt.*;
class list extends JFrame {
list(String title) {
setTitle(title);
setLocation(300, 100);
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel igna = new JPanel();
JPanel igna1 = new JPanel();
JPanel igna2 = new JPanel();
JButton B1 = new JButton("BACK");
JButton B2 = new JButton("NEXT");
JLabel lab = new JLabel("SILAKAN PILIH BUAH FAVORIT MU");
JList made = new JList(new String[] { "Apel", "Mangga", "Anggur",
"Alpokat", "Jeruk", "Pisang", "Strawbery", "Nanas", "Nangka",
"Kedondong", "Pepaya" });
igna.setBackground(Color.gray);
igna.add(lab);
igna.add(made);
lab.setFont(new Font("Arial", Font.BOLD, 11));
made.setFont(new Font("Vijaya", Font.BOLD, 14));
lab.setForeground(Color.yellow);
made.setBackground(Color.green);
made.setForeground(Color.red);
igna.setLayout(new GridLayout(1, 1));
add(igna);
add(igna, BorderLayout.NORTH);
igna1.add(B1);
igna1.add(B2);
add(igna1);
igna1.setBackground(Color.black);
add(igna1, BorderLayout.SOUTH);
add(igna2);
igna2.setBackground(Color.pink);
add(igna2, BorderLayout.CENTER);
setVisible(true);
}
public static void main(String args[]) {
list IGNA = new list("Ignatius JList Program");
}
}
0 komentar:
Posting Komentar