java GUI編程(swing)之四swing下拉框,列表框,滾動窗口

下拉框(JComboBox)
列表框(JList)
滾動窗口(JScrollPane)
 
package gui;
import java.awt.GridLayout;
import javax.swing.*;
 
/**
* 下拉框,列表框,窗口滾動
* Created by admin on 2017/7/9.
*/
public class Scroll extends JFrame{
// 定義須要用到的組件
private JList jList;
private JComboBox jComboBox;
private JScrollPane jScrollPane;
private JLabel jLabel, jLabel2;
private JPanel jPanel, jPanel2;
public static void main(String[] args){
Scroll scroll = new Scroll();
}
public Scroll(){
jPanel = new JPanel();
jPanel2 = new JPanel();
jLabel = new JLabel("所在省");
jLabel2 = new JLabel("所在市");
String [] province = {"廣西", "廣東", "湖南"};
// 下拉框
jComboBox = new JComboBox(province);
String [] city = {"南寧", "柳州", "廣州","深圳", "長沙"};
// 列表框
jList = new JList(city);
jList.setVisibleRowCount(3);
// 窗口滾動
jScrollPane = new JScrollPane(jList);
this.setLayout(new GridLayout(2, 1));
jPanel.add(jLabel);
jPanel.add(jComboBox);
 
jPanel2.add(jLabel2);
jPanel2.add(jScrollPane);
 
this.add(jPanel);
this.add(jPanel2);
this.setTitle("Java");
this.setLocation(500, 250);
this.setSize(350, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
相關文章
相關標籤/搜索