JAVA 问题 JScrollPane

2025-01-26 02:32:29
推荐回答(1个)
回答1:

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
/**
*
* @author xiaobao
*
*/
public class Test{
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){

public void run() {
JFrame frame = new TestFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

});
}
}
class TestFrame extends JFrame{
public TestFrame(){
setTitle("Test");
setSize(WIDTH,HEIGHT);
String[] word = {"1","2","3","4","5","6","7","8"};
JList list = new JList(word);
list.setVisibleRowCount(4);

setLayout(new BorderLayout());
add(new JScrollPane(list),BorderLayout.NORTH);
}
private static final int WIDTH = 200;
private static final int HEIGHT = 200;
}
JLIST自身是没有滚动条的,不可能有