具体的函数是什么,是不是我的说法“无效区域”不对,我在网上没查到

解决方案 »

  1.   

     private void paintCompent(Graphics g){}
      

  2.   

    class MyPanel extend JPanel
    {
    OtherClass cla;
    ..........
    }
    class OtherClass
    {
    //
    //我想在这里重绘或者发出重绘事件,请问我应该怎么做,谢谢
    }
      

  3.   

    8好意思,最近没怎么关注swing这块,早忘啦
      

  4.   

    搜索到几个网址,你研究一下吧:
    http://stackoverflow.com/questions/4392722/how-to-repaint-a-jpanel-after-have-drawn-on-ithttp://stackoverflow.com/questions/2155351/swing-jpanel-wont-repaint
      

  5.   

    Java的GUI不会啊,Java的GUI在现在市场并不大,最好不要做太多研究(除非想从事GUI的工作)。
      

  6.   

    It depends on what you want to happen and what layout managers are in use, but the basic rules are:Make sure update is called on the EDT. If it's not (SwingUtilities.isEventDispatchThread()returns false) you will need to use SwingUtilities.invokeLater to schedule the update on the EDT. For example:SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            update();
        }});
    Call invalidate(). Most things that change a component will do this for you. So you only need to call this if the following does not work on its own.Call validate() on the highest affected component. This is probably the muddiest bit of Java's rendering cycle. The call to invalidate s the component and all of its ancestors as needing layout. The call to validate performs the layout of the component and all of its descendants. One works "up" and the other works "down". You need to call validate on the highest component in the tree that will be affected by your change.Also, calling validate on a top-level component (JWindow, JDialog, JFrame) will not necessarily resize that component. To make that happen, you'll need to call pack() or setSize().If your changes alter the size or position of containers, The resized containers will repaint, but they will not erase the space the used to occupy. Calling repaint() on the parent of the container will cause it to repaint the background, correcting the damage.找到的一点资料,不知说的对不对
      

  7.   


    首先,你建立了自己的MyPanel,可以重载 paintCompent(Graphics g){}
    其次,你想在 OtherClass 中来请求对 MyPanel 重绘,可以将MyPanel作为一个参数传给OtherClass 的实例,通过该参数来调用MyPanel 的repaint()方法
      

  8.   

    在OtherClass中直接使用MyPanel.this.repaint();就行了。重画的内容写在MyPanel的void paintCompent(Graphics g);方法中。