日期:2014-05-20 浏览次数:21232 次
import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; public class textarea2 implements ListSelectionListener { String[] listEntries = {"alpha","bata","gama","delta","epsilon","zeta","eta","theta"}; JList llist = new JList(listEntries); public static void main(String[] args) { textarea2 gui = new textarea2(); gui.go(); } public void go() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); llist.setVisibleRowCount(4); llist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); llist.addListSelectionListener(this); JScrollPane scroller = new JScrollPane(llist); scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS ); scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); frame.getContentPane().add(BorderLayout.CENTER,scroller); frame.setSize(350,300); frame.setVisible(true); } public void valueChanged(ListSelectionEvent e) { } }
import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; public class TextArea2 implements ListSelectionListener { String[] listEntries = {"alpha","bata","gama","delta","epsilon","zeta","eta","theta"}; JList<String> llist = new JList<>(listEntries); public static void main(String[] args) { TextArea2 gui = new TextArea2(); gui.go(); } public void go() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); llist.setVisibleRowCount(4); llist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); llist.addListSelectionListener(this); JScrollPane scroller = new JScrollPane(llist); scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS ); scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); frame.getContentPane().add(BorderLayout.CENTER,scroller); frame.setSize(350,300); frame.setVisible(true); } public void valueChanged(ListSelectionEvent e) { } }