我写了一个component组件. 目的是想画一个我自己订制的边框以及文字显示的效果.
其父类是JComponent.
我覆盖了其中的paintComponent(Graphics g),在其中加了些画法.
同时用setBorder(new Border()); 给它加了一个我需要的边框.
刚开始,还是能正确显示出来,但是,当我切换一下窗口,再显示,整个java窗口全变灰了,除了我画的那个特殊的component.但是我如果用一个clone 的component来画border. 则结果是正确的,请问那为达人知道这是为什么?附部分代码:
public CustomComponent
{
...    protected void paintComponent(Graphics g)
    {
         ...
copy.setBorder(new LineBorder(new Color(borderColor), (short)borderWidth, (short)top, (short)left, (short)bottom, (short)right));
...

}...
}(LineBorder 也是我自己写的个一个border);

解决方案 »

  1.   

    是因为你的component处于最上方,作为高亮显示的
      

  2.   

    protected void paintComponent(Graphics g)
        {
     super.paintComponent(Graphics g);
             ...
    copy.setBorder(new LineBorder(new Color(borderColor), (short)borderWidth, (short)top, (short)left, (short)bottom, (short)right));
    ...}
      

  3.   

    protected void paintComponent(Graphics g)
        {
     super.paintComponent(g);
             ...
    copy.setBorder(new LineBorder(new Color(borderColor), (short)borderWidth, (short)top, (short)left, (short)bottom, (short)right));
    ...}