码迷,mamicode.com
首页 > 编程语言 > 详细

java GUI编程(swing)之四swing下拉框,列表框,滚动窗口

时间:2018-01-13 18:43:31      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:extend   hit   定义   tle   oid   java   pre   create   style   

下拉框(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);
}
}
 
 
 
 
 

java GUI编程(swing)之四swing下拉框,列表框,滚动窗口

标签:extend   hit   定义   tle   oid   java   pre   create   style   

原文地址:https://www.cnblogs.com/SunshineLittleCat/p/8279917.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!