@Override protected void paintComponent(Graphics g) { if (!active) { return; } super.paintComponent(g); }
@Override protected void paintComponent(final Graphics pG) { super.paintComponent(pG); if (placeholder == null || placeholder.length() == 0 || getText().length() > 0) { return; } final Graphics2D g = (Graphics2D) pG; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.lightGray); g.drawString(placeholder, getInsets().left, pG.getFontMetrics().getMaxAscent() + getInsets().top); }
@Override protected void paintComponent(final Graphics pG) { super.paintComponent(pG); if (placeholder.length() == 0 || getText().length() > 0) { return; } final Graphics2D g = (Graphics2D) pG; g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(getDisabledTextColor()); g.drawString(placeholder, getInsets().left, pG.getFontMetrics() .getMaxAscent() + getInsets().top); }
@Override public void paintComponent(Graphics g) { Component window = this.getTopLevelAncestor(); if (window instanceof Window && !((Window) window).isOpaque()) { // This is a translucent window, so we need to draw to a buffer // first to work around a bug in the DirectDraw rendering in Swing. int w = this.getWidth(); int h = this.getHeight(); if (buffer == null || buffer.getWidth() != w || buffer.getHeight() != h) { // Create a new buffer based on the current size. GraphicsConfiguration gc = this.getGraphicsConfiguration(); buffer = gc.createCompatibleImage(w, h, BufferedImage.TRANSLUCENT); } // Use the super class's paintComponent implementation to draw to // the buffer, then write that buffer to the original Graphics object. Graphics bufferGraphics = buffer.createGraphics(); try { super.paintComponent(bufferGraphics); } finally { bufferGraphics.dispose(); } g.drawImage(buffer, 0, 0, w, h, 0, 0, w, h, null); } else { // This is not a translucent window, so we can call the super class // implementation directly. super.paintComponent(g); } } }
@Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setColor(getBackground()); g2.fillRect(0, 0, getWidth(), getHeight()); g2.translate(0, 9); super.paintComponent(g); g2.translate(0, -9); if (!getHint().isEmpty() && getPassword().length == 0 && (getLabel().isEmpty() || isFocusOwner()) && floatingLabel.isFloatingAbove()) { g.setFont(Roboto.REGULAR.deriveFont(16f)); g2.setColor(Utils.applyAlphaMask(getForeground(), HINT_OPACITY_MASK)); FontMetrics metrics = g.getFontMetrics(g.getFont()); g.drawString(getHint(), 0, metrics.getAscent() + 36); } floatingLabel.paint(g2); g2.setColor(Utils.applyAlphaMask(getForeground(), LINE_OPACITY_MASK)); g2.fillRect(0, getHeight() - 9, getWidth(), 1); g2.setColor(accentColor); g2.fillRect((int) ((getWidth() - line.getWidth()) / 2), getHeight() - 10, (int) line.getWidth(), 2); }