GUI JList列表框练习二

package swing;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Vector;

public class sandemo2 extends JFrame{
	JList list1,list2;
	Container container;
	public sandemo2() {
		container=this.getContentPane();
		this.setLayout(new GridLayout(1,2));
		String []str= {"北京","上海","杭州","深圳"};
		Vector <String>vector=new Vector<String>();
		vector.add("篮球");
		vector.add("乒乓球");
		vector.add("跑步");
		list2=new JList(vector);
		list1=new JList(str);
		list1.setBorder(BorderFactory.createTitledBorder("你喜欢的城市"));
		list2.setBorder(BorderFactory.createTitledBorder("你喜欢的运动是"));
		list1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		list2.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);//设置标题
		container.add(list1);
		container.add(list2);
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		this.setTitle("列表框练习二");
		this.setSize(600,450);
		this.show();
	}
	public static void main(String []args) {
		new sandemo2();
	}
}

  运行结果:

原文地址:https://www.cnblogs.com/mianyang0902/p/10888549.html

时间: 2024-11-15 04:33:26

GUI JList列表框练习二的相关文章

GUI JList列表框练习

package swing; import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; public class sandemo extends JFrame{ JList list1,list2; Container container; sandemo(){ container=this.getContentPane(); list1=new JList(); S

列表框空间JList的用法演示

package 列表框控件演示; import java.awt.Color; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.BorderFactory; imp

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 j

Java Swing界面编程(30)---列表框:JList

列表框可以同时将多个选项信息以列表的方式展现给用户,使用JList可以构建一个列表框. package com.beyole.util; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Vector; import javax.swing.BorderFact

Java Swing编程接口(30)---列表框:JList

列表框同时可以在信息呈现给用户的列表多个选项,使用JList能够建立一个列表框. package com.beyole.util; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Vector; import javax.swing.BorderFactory

NX二次开发-Block UI C++界面List Box(列表框)控件的获取(持续补充)

1 获得当前选择的 2 //列表框控件 3 PropertyList* ExpressionListProperties = list_box0->GetProperties(); 4 std::vector<NXOpen::NXString> listStrings = ExpressionListProperties->GetStrings("ListItems"); 5 std::vector<int> index = ExpressionLi

Swing列表框组件

public class JListTest extends JFrame{    private static final long serialVersionUID=1L;        public JListTest()    {        Container cp=getContentPane();        cp.setLayout(null);        JList<String> jl=new JList<>(new MyListModel());  

20151214学习内容:Web之列表框

列表框: ListBox 1. 绑定数据 方法一: testDataContext context = new testDataContext(); ListBox1.DataSource = context.Nation; ListBox1.DataValueField = "Code"; ListBox1.DataTextField = "Name"; ListBox1.DataBind(); 绑定数据 方法二: ListItem item = new List

积累的VC编程小技巧之列表框

1.列表框中标题栏(Column)的添加 创建一个List Control,其ID为IDC_LIST,在其Styles属性项下的View项里选择Report.Align项里选择Top.Sort项里选择None. 然后在该List所在对话框的类(头文件)里创建ClistCtrl的一个对象m_list然后在.cpp文件的OnInitDialog()之类的函数里实现如下代码: CString strname[3]; strname[0]="Screen Name"; strname[1]=&