JToolTip 内添加 Html 标记就可以换行了,你可以自己试试!一个JFrame的JAVA程序,其contentPane上add了许多JPanel,拖动窗口出屏幕以后拖回来,被覆盖的部分没有被重画,应该重载哪些方法,JFrame.paintComponents()???JFrame 拖动后会调用 paint() 函数,重绘窗口,但这是自动的啊!
如果你在 JFrame 里使用的 都是完整的(有自己的绘制功能)控件,它是会自己调用的,不用做任何的修改的.你的应该是代码本身出了问题,把代码贴出来看看就知道了.

解决方案 »

  1.   

    我把相关代码贴出来,我跟终到原因,是我在一个JPanel中add了一个自定义的继承自JPanel的类实例
    包含main()的文件package tri.dts.pf.monitor;import java.awt.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class UserIconPool extends JPanel {
      XYLayout xYLayout1 = new XYLayout();  Point firstIconPos = new Point(45,35);
      boolean placeRandom = false;
      int colCnt = 0;
      int rowCnt = 0;  public UserIconPool() {
        try {
          jbInit();
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }
      }
      private void jbInit() throws Exception {
        this.setLayout(xYLayout1);
        this.setBackground(Color.cyan);
        this.setBackground(MainDisp.USER_PANE_COLOR);
        this.add(new UserIcon(80),new XYConstraints(80,80,0,0));
      }  public static void main(String[] argc) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setLocation(80,80);
        UserIconPool userIconPool = new UserIconPool();
        frame.setSize(600,600);
        Container contentPane = frame.getContentPane();
        contentPane.add(userIconPool,null);
        frame.setVisible(true);
      }
    }相关文件UserIcon.java,我自己写的可拖动的一个对象
    package tri.dts.pf.monitor;import java.awt.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import java.awt.event.*;
    import java.text.NumberFormat;
    import com.borland.jbcl.layout.*;
    import javax.swing.ToolTipManager;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2004</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class UserIcon
        extends JPanel {
      int seq;  int curMouseX;
      int curMouseY;
      UserIconPool parent;
      JLabel jLabel1 = null;
      TextLabel jLabel2 = null;
      ImageIcon imageIcon1 = null;
      BoxLayout2 boxLayout21 = new BoxLayout2();
      String toolTipText = "<html>错误<br><font color='red'>没有设置正确的弹出信息</font></html>";
      UserIcons userIcons = UserIcons.getInstance();  ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
      public UserIcon(int seq) {
        this.seq = seq;
        try {
          jbInit();
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }
      }  private void jbInit() {
        toolTipManager.registerComponent(this);
        this.setPreferredSize(new Dimension(100, 100));
        this.setLayout(boxLayout21);
        this.addMouseMotionListener(new this_Mouse_Motion_Adapter(this));    NumberFormat format = NumberFormat.getNumberInstance();
        format.setMinimumIntegerDigits(3);    imageIcon1 = userIcons.getUserIcon((int)Math.floor(Math.random()*10));
        jLabel1 = new JLabel(imageIcon1);
        jLabel2 = new TextLabel("用户"+format.format(seq),12,new Point(0,0));
        jLabel2.setPreferredSize(new Dimension(45,15));
        boxLayout21.setAxis(BoxLayout.PAGE_AXIS);
        this.add(jLabel1, null);
        jLabel1.setAlignmentX(Component.CENTER_ALIGNMENT);
        this.add(jLabel2, null);
        jLabel2.setAlignmentX(Component.CENTER_ALIGNMENT);
        this.setPreferredSize(new Dimension(Math.max(imageIcon1.getIconWidth(),
                                                     jLabel2.getPreferredSize().
                                                     width),
                                            imageIcon1.getIconHeight() +
                                            jLabel2.getPreferredSize().height));
        this.setToolTipText(toolTipText);
      }  public void mouseMovePerformed(MouseEvent e) {
        curMouseX = e.getX();
        curMouseY = e.getY();
      }  public void mouseDraggedPerformed(MouseEvent e) {
        parent = (UserIconPool)getParent();
        int newMouseX = e.getX();
        int newMouseY = e.getY();
        Point nextPoint = null;
        Point newPoint = this.getLocation();
        if ( (newMouseX + newPoint.x) > parent.getWidth() ||
            (newMouseY + newPoint.y) > parent.getHeight() ||
            (newMouseX + newPoint.x) < 0 ||
            (newMouseY + newPoint.y) <0) {
          return;
        }
        nextPoint = new Point(newPoint.x + (newMouseX - curMouseX),
                              newPoint.y + (newMouseY - curMouseY));
        UserIconPool pool = (UserIconPool) getParent();
        pool.remove(this);
        pool.add(this, new XYConstraints(nextPoint.x, nextPoint.y, 0, 0));
        this.revalidate();
        repaint();
      }  public static void main(String[] argc) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(200, 200);
        UserIcon userIcon = new UserIcon(5);
        frame.getContentPane().add(userIcon);
        frame.setVisible(true);
      }
    }class this_Mouse_Motion_Adapter
        extends MouseMotionAdapter {
      private UserIcon adaptee;
      public this_Mouse_Motion_Adapter(UserIcon adaptee) {
        this.adaptee = adaptee;
      }  public void mouseMoved(MouseEvent e) {
        adaptee.mouseMovePerformed(e);
      }  public void mouseDragged(MouseEvent e) {
        adaptee.mouseDraggedPerformed(e);
      }
    }
      

  2.   

    如果你覆盖了父类的方法,别忘了调用super.方法();在画图的时候经常出现这种问题。
    代码太长,你自己看看吧
      

  3.   

    不会是机器慢吧?256MB/512MB流畅
      

  4.   

    我是IBM品牌机,3G的cpu,1G的内存,镭9500双头输出到双17'液晶
    应该不是机器慢吧?我知道程序有问题,我在找原因。
      

  5.   

    IBM品牌机,3G的cpu,1G的内存,够酷
      

  6.   

    我对这个不怎么熟悉不过我觉得如果你覆盖了父类的方法,别忘了调用super.方法();在画图的时候经常出现这种问题。这个说的没错.
      

  7.   

    我找到原因了,在UserIcon.mouseDraggedPerformed(MouseEvent e)函数的最后一行调用了
    repaint()函数,去掉就没有问题了。但是不太清楚为什么。