rt :
-------------------------------------------------------------
            Quietly through  .....

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【hardtoregistration】截止到2008-07-10 17:08:40的历史汇总数据(不包括此帖):
    发帖的总数量:12                       发帖的总分数:330                      每贴平均分数:27                       
    回帖的总数量:537                      得分贴总数量:106                      回帖的得分率:19%                      
    结贴的总数量:11                       结贴的总分数:310                      
    无满意结贴数:2                        无满意结贴分:40                       
    未结的帖子数:1                        未结的总分数:20                       
    结贴的百分比:91.67 %               结分的百分比:93.94 %                  
    无满意结贴率:18.18 %               无满意结分率:12.90 %                  
    值得尊敬
      

  2.   

    -------------------------------------------------------------
                Quietly through  .....
      

  3.   

    怎么刷新?你说的是哪个?        new JPanel().updateUI();
            new JPanel().repaint();
            new JPanel().validate();        
            new JPanel().revalidate();
      

  4.   

    确认一下,当用户点击了某个按钮的时候才去刷新JPanel。假设按钮事件的执行时间是2秒中,JPanel的刷新是不是要在按钮事件执行完之后才会显示??
    -------------------------------------------------------------
                Quietly through  .....
      

  5.   

    我在SWT上测试过,SWT中: 
    在按钮事件中调用方法刷新组件(同时还执行些别的方法,如sleep(1000)),只有在按钮事件完全执行完之后,刷新后的界面才能显示出来。估计Swing应该也一样。如果想用户一点击按钮就刷新,而不是sleep(1000)之后在刷新,只能重启一个线程了-------------------------------------------------------------
                Quietly through  .....
      

  6.   


    /*
     * Created on July 10 2008
     * 
     * Copyright by 布谷鸟
     */
    package swt;import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.SelectionAdapter;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.graphics.Color;
    import org.eclipse.swt.graphics.Image;
    import org.eclipse.swt.widgets.Button;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Label;
    import org.eclipse.swt.widgets.Shell;/**
     * 
     * @author cuckoo
     * 
     */
    public class RefreshTry { public static void main(String args[]) {
    new RefreshTry().createShell();
    } private void createShell() {
    _shell = new Shell(_display, SWT.MIN);
    _shell.setSize(300, 200);
    _shell.setText("Refresh Contents");
    createContents();
    _shell.open();
    while (!_shell.isDisposed()) {
    if (!_display.readAndDispatch()) {
    _display.sleep();
    }
    }
    _display.dispose();
    } private void createContents() {
    final Button button = new Button(_shell, SWT.PUSH);
    button.setBounds(2, 2, 100, 20);
    button.setText("Click me");
    displayLabel = new Label(_shell, SWT.SHADOW_IN);
    displayLabel.setText("Default ....");
    displayLabel.setBounds(10, 50, 40, 20); _methodLabel = new Label(_shell, SWT.SHADOW_ETCHED_OUT);
    _methodLabel.setBackground(new Color(_display, 0, 0, 0));
    _methodLabel.setForeground(new Color(_display, 140, 140, 140));
    _methodLabel.setBounds(120, 50, 100, 15); button.addSelectionListener(new SelectionAdapter() {
    public void widgetSelected(SelectionEvent e) {
    // TODO Auto-generated method stub
    displayLabel.setBounds(10, 50, 40, 40);
    displayLabel.setText("");
    displayLabel
    .setBackgroundImage(new Image(_display, "89_m.bmp"));
    // sleep one minutes
    processThread();
    }
    });
    } private void processThread() {
    Thread thread = new Thread() {
    public void run() {
    // TODO Auto-generated method stub
    _display.asyncExec(new Runnable() {
    public void run() {
    // TODO Auto-generated method stub
    int i = 0;
    while (i <= 30) {
    if (i != 30) {
    _methodLabel.setText("当前值为: " + i);
    } else {
    if (i == 30) {
    _methodLabel
    .setText("方法调用结束 ");
    Image image = new Image(_display,
    "89_m.bmp");
    displayLabel.setBackgroundImage(image);
    displayLabel.setSize(
    image.getBounds().width, image
    .getBounds().height);
    }
    }
    try {
    Thread.sleep(100);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    i ++ ;
    }
    }
    }); }
    };
    thread.start();
    } private Shell _shell = null;
    private Label _methodLabel = null;
    private Label displayLabel = null;
    private Display _display = Display.getDefault();
    }
    -------------------------------------------------------------
                Quietly through  .....