📄 testjlists.java
字号:
/* * TestJLists.java * * Created on July 30, 2002, 2:36 PM */package ch16;import javax.swing.*;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;/** * * @author Stephen Potts * @version */public class TestJLists extends JFrame implements ListSelectionListener{ JList lstBread; JTextField tField; /** Creates new TestJLists*/ public TestJLists() { String[] names = {"White Bread", "Wheat Bread", "Rye Bread"}; lstBread = new JList(names); lstBread.addListSelectionListener(this); tField = new JTextField(" ",20); getContentPane().setLayout(new FlowLayout()); getContentPane().add(lstBread); getContentPane().add(tField); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Using JLists"); setBounds( 100, 100, 300, 300); setVisible(true); } public void valueChanged(ListSelectionEvent lse) { String selection = ""; if (lse.getValueIsAdjusting()) { return; } int[] selected = lstBread.getSelectedIndices(); for(int i=0; i < selected.length; ++i) { selection = selection + " " + (String) lstBread.getModel().getElementAt(selected[i]); tField.setText(selection); } } public static void main(String[] args) { TestJLists tc = new TestJLists(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -