在mouseentered()方法上再次重写paintborder()方法

neskvpey  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(155)

我正在学习java的外观和感觉,所以我想要的是覆盖 paintBorder() 属于 JTextField 再一次。当我再说一遍,这意味着我有自己的外观和感觉 JTextField 具有弯曲的拐角(通过覆盖 paintBorder() )那我有一个 MouseAdapter 即hover类将某些组件悬停在一个类中。
现在我怎样才能覆盖 paintBorder() 在我的悬停课上?
这是我的 JTextField
我试着用 setBorder() 在hover类中,但它会在其原始组件上创建边框,如下所示。

那么有人能教我如何超越 paintBorder() 在hover类上再次使用方法?还是更改自定义边框颜色的更好解决方案?
额外代码:

//How I created the border at my own Look and Feel
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.black);
g2.drawRoundRect(0, 0, getWidth()-1, getHeight()-1, horizontalDiameter, verticalDiameter);//hDiameter and vDiamater are both 15
super.paintBorder(g);

在我的悬停类中:

if(e.getComponent() instanceof JTextField)
{
   JTextField textField = (JTextField) e.getComponent();
   textField.setBorder(BorderFactory.createLineBorder(Color.black));//The wrong code
   //???
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题