怎么样才能使Jscrollpane区域的内容随着滚动条拖动显示出来,我的程序总是要手动刷新才能出来 拖动出不来,求教大侠帮我看看?
import javax.swing.*;import java.awt.*;
public class Cai {
private JFrame _frame;
private JPanel _panelMain;
private JPanel _panelCai;
private JPanel _panelArea;
private JButton _bntCai;
private JTextArea _txtArea;
private JLabel _lbl;
private JTextField _txt;
private JScrollPane _jsp;
public Cai() {
_frame = new JFrame();
_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//点击右上角的关闭按钮时退出程序运行
_panelMain = new JPanel(new BorderLayout());
_panelCai = new JPanel();
_lbl = new JLabel("请猜1-10之间的数字:");
_txt = new JTextField(3);
_bntCai = new JButton("猜");
_panelArea = new JPanel(new BorderLayout());
//设置BorderLayout,让_txtArea自动充满
_txtArea = new JTextArea();
_txtArea.setLineWrap(true);
//_txtArea自动换行
JPanel j=new JPanel();
j.setLayout(new GridLayout(50,2));
for(int i=0;i<100;i++)
{ Checkbox[] box=new Checkbox[100];
box[i]=new Checkbox("haha"+i);
j.add(box[i]);
j.updateUI();
j.validate();
}
j.updateUI();
_jsp = new JScrollPane(j);
// _jsp 以_panelArea为Viewport
_jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
_jsp.setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
_jsp.updateUI();
_jsp.validate();
_panelArea.add(_txtArea);
_panelCai.add(_lbl);
_panelCai.add(_txt);
_panelCai.add(_bntCai);
_panelMain.add(_panelCai, BorderLayout.NORTH);
_panelMain.add(_jsp, BorderLayout.CENTER);
//添加_jsp在 BorderLayout.CENTER
_frame.setContentPane(_panelMain);
_frame.setBounds(300, 300, 300, 300);
_frame.setVisible(true);
_frame.show();
_frame.validate();
}
public static void main(String[] args) {
Cai a = new Cai();
}
} --------------------编程问答-------------------- 每次要显示拖动出来的部分都要手动去刷新 --------------------编程问答-------------------- 代码有点乱。
for(int i=0;i<100;i++)
{ Checkbox[] box=new Checkbox[100];
要1w个Checkbox,什么情况?
补充:Java , Java SE