import java.awt.BorderLayout;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class SizingSamples {
public static void main(String args[]) {
String labels[] = { "A", "B", "C", "D", "E", "F" ,"G","H","I","J"};
JFrame frame = new JFrame("Sizing Samples");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JList jlist1 = new JList(labels);
jlist1.setVisibleRowCount(4);
DefaultListModel model = new DefaultListModel();
model.ensureCapacity(100);
for (int i = 0; i < 100; i++) {
model.addElement(Integer.toString(i));
}
JScrollPane scrollPane1 = new JScrollPane(jlist1);
frame.add(scrollPane1, BorderLayout.NORTH);
JList jlist2 = new JList(model);
jlist2.setVisibleRowCount(4);
jlist2.setFixedCellHeight(12);
jlist2.setFixedCellWidth(200);
JScrollPane scrollPane2 = new JScrollPane(jlist2);
frame.add(scrollPane2, BorderLayout.CENTER);
JList jlist3 = new JList(labels);
jlist3.setVisibleRowCount(4);
frame.add(jlist3, BorderLayout.SOUTH);
frame.setSize(300, 350);
frame.setVisible(true);
}
}
|