欢迎来到天天文库
浏览记录
ID:37852646
大小:198.50 KB
页数:4页
时间:2019-06-01
《java修改列表项选择模式》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、修改列表框选择模式packagecom.swing01;importjava.awt.BorderLayout;importjava.awt.EventQueue;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.border.EmptyBorder;importjavax.swing.UIManager;importjava.awt.GridLayout;importjavax.swing.JScrollPane;importjavax.swing.JList;importjava.aw
2、t.event.WindowAdapter;importjava.awt.event.WindowEvent;importjavax.swing.ListSelectionModel;importjavax.swing.JLabel;importjavax.swing.SwingConstants;importjava.awt.Font;publicclassJListSelectModelTestextendsJFrame{/****/privatestaticfinallongserialVersionUID=-1203078038045289207L;//面板priv
3、ateJPanelcontentPane;//列表1privateJListlist1;privateJListlist2;privateJListlist3;//标签privateJLabellabel1;privateJLabellabel2;privateJLabellabel3;/***Launchtheapplication.*/publicstaticvoidmain(String[]args){try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");}ca
4、tch(Throwablee){e.printStackTrace();}EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{JListSelectModelTestframe=newJListSelectModelTest();frame.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}/***Createtheframe.*/publicJListSelectModelTest(){addWindowListener(newWindo
5、wAdapter(){@OverridepublicvoidwindowActivated(WindowEvente){do_this_windowActivated(e);}});//标题setTitle("力天教育:列表框的显示模式");//退出时关闭虚拟机setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//大小及显示位置setBounds(100,100,450,300);//面板容器contentPane=newJPanel();//面板容器的边框contentPane.setBorder(newEmptyBorder(
6、5,5,5,5));//布局格式contentPane.setLayout(newBorderLayout(0,0));//将面板容器加入到我们的窗体中setContentPane(contentPane);//面板创建JPanelpanel=newJPanel();//将面板另入到容器面板中contentPane.add(panel,BorderLayout.CENTER);//面板布局格式panel.setLayout(newGridLayout(1,3,5,5));//滚动条JScrollPanescrollPane1=newJScrollPane();//为面板添加
7、滚动条panel.add(scrollPane1);//列表的创建list1=newJList();//设置列表的标题list1.setFont(newFont("微软雅黑",Font.PLAIN,14));//setSelectionMode确定允许单项选择还是多项选择//ListSelectionModel该组件显示一个具有稳定索引的值列表//SINGLE_SELECTION一次选择一个列表索引list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
此文档下载收益归作者所有