实现圆角矩形边框,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
自动文本 Java Swing 库,允许将自动完成的可能性添加到文本组件(JTextComponent - JTextField - JFormattedTextField 等)
2021-07-14 13:03:41 26KB Java
1
JTextField及JPasswordField的空值处理,思路是采用图层Lable,并利用lable的无点击特性,类似ios文本框的空值默认显示。
2021-06-10 16:59:40 14KB java swing JTextField
1
public void color() { int i, f; String mad = ""; String h = jTextArea1.getText(); i = jTextField1.getText().length(); Highlighter hilite = jTextArea1.getHighlighter();//获取负责进行高亮显示的对象 //Highlighter:一个允许用户用带有颜色的区域标出背景的对象接口 for (f = 0; f < h.length(); f++) { if (i < h.length()) { mad = h.substring(f, i++).toString(); //System.out.println(str); } if (jTextField1.getText().compareToIgnoreCase(mad) == 0) { try { int g = jTextField1.getText().length(); //向视图添加高亮显示 hilite.addHighlight(f, f + g, new MyHighlightPainter(Color.PINK)); // jTextArea1.select(f, f+i); // jTextArea1.setSelectionColor(Color.RED); // System.out.println("成功了!"); } catch (BadLocationException ex) { Logger.getLogger(newsos.class.getName()).log(Level.SEVERE, null, ex); } } } }
2020-02-01 03:07:39 1KB jTextField
1