实现圆角矩形边框,hint文字,主要代码:
Graphics2D g2d=(Graphics2D) g;
g2d.setStroke(new BasicStroke(2,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.5f));
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(borderColor);
g2d.drawRoundRect(0, 0, c.getWidth()-4,c.getHeight()-4, 20, 20);
JTextField textField = (JTextField) c;
if ("".equals(textField.getText()))
{
g2d.setColor(Color.BLACK);
g2d.drawString("请输入文字...", 10, 18);
}
2021-07-27 18:10:34
12KB
java
1