ToolTipText 背景颜色设置,边框设置?怎么弄呢?就是在给控件setToolTipText()时,怎么改变背景颜色,边框设置呢?

解决方案 »

  1.   


    ToolTipText 背景颜色设置,边框设置?怎么弄呢? 就是在给控件setToolTipText()时,怎么改变背景颜色,边框设置呢?
    比如说:jLabel1.setToolTipText("asd"),怎么改变asd的背景色,边框设置。?麻烦给个例子说明哈呢。。谢谢先
      

  2.   

    ToolTipText 背景颜色设置,边框设置?怎么弄呢? 就是在给控件setToolTipText()时,怎么改变背景颜色,边框设置呢? 
    比如说:jLabel1.setToolTipText("asd"),怎么改变asd的背景色,边框设置。? 麻烦给个例子说明哈呢。。谢谢先
      

  3.   

    设置的文本用 html 标签字符串
      

  4.   

    不太完美的方案,希望大家多多指点!@Override
    public void createPartControl(Composite parent) {

    final Composite top = new Composite(parent, SWT.NONE);
    GridLayout topLayout = new GridLayout(2, false);
    top.setLayout(topLayout);

    Label label = new Label(top, SWT.NONE);
    label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,false));
    label.setText("Name:");

    final Text text = new Text(top, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    text.setText("");

    final Color bgColor = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_RED);
    final Color fgColor = PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLACK);

    final AtomicReference<Integer> x = new AtomicReference<Integer>();
    final AtomicReference<Integer> y = new AtomicReference<Integer>();


    text.addMouseTrackListener(new MouseTrackAdapter(){ public void mouseHover(MouseEvent e) {
     x.set(e.x);
     y.set(e.y);
     text.redraw();
    }

    });

    text.addPaintListener(new PaintListener(){ public void paintControl(PaintEvent e) {
    GC gc = e.gc;
            
    if(x.get() != null && y.get() != null){
            Rectangle rect  = new Rectangle(x.get(),y.get(),100,20);
            gc.setBackground(bgColor);
            gc.setForeground(fgColor);
    gc.fillRectangle(rect);
    gc.drawText("Hello, it works!", rect.x, rect.y);

    }       

    }

    });



    }
      

  5.   

       用html标签可以实现颜色和字体的改变 
       如:setToolTipText("<html><font color="#123456">nihao</font></html>");
      

  6.   

    虽然是老贴,但也许有人会看到,还是回复一下。答案是正确的有效的;以JButton为例:
    class MyButton extends JButton {
       @Override
       public JToolTip createToolTip() {
          JToolTip jt = super.createToolTip();
          jt.setBackground(Color.WHITE);
          jt.updateUI();
          return jt;
       }
    }
    例子中将toolTipText的背景变成白色的了。
    用MyButton声明你的实例,就行了