/** Convers a color to a string. */ static public String toString (Color color) { if (color == null) throw new IllegalArgumentException("color cannot be null."); String r = Integer.toHexString(color.getRed()); if (r.length() == 1) r = "0" + r; String g = Integer.toHexString(color.getGreen()); if (g.length() == 1) g = "0" + g; String b = Integer.toHexString(color.getBlue()); if (b.length() == 1) b = "0" + b; return r + g + b; }
private JFrame frame = new JFrame("sssssssss"); private JButton tip1Null = new JButton(" test button "); ((Graphics2D) g).setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(color); g.drawRoundRect(x, y, width, height, MARGIN, MARGIN); final Color color1 = new Color(230, 255, 255, 0); final Color color2 = new Color(255, 230, 255, 64); final Color alphaColor = new Color(200, 200, 230, 64); final Color color3 = new Color( alphaColor.getRed(), alphaColor.getGreen(), alphaColor.getBlue(), 0); final Color color4 = new Color( alphaColor.getRed(), alphaColor.getGreen(), alphaColor.getBlue(), 64); super.paint(g, c); Graphics2D g2D = (Graphics2D) g; g2D.setPaint(gradient1); g2D.fill(rec1); paintText(g, b, b.getBounds(), b.getText()); g.setColor(Color.red.brighter()); g.fillRect(0, 0, b.getSize().width, b.getSize().height);
Graphics2D g2d = (Graphics2D) g.create(); g2d.setColor(new Color(0xFFAA00)); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setStroke(basicStroke); g2d.drawRoundRect(3, 3, getWidth()-4, getHeight()-4, archH, archH); setLayout(new GridBagLayout()); add(usrNameLabel, labCnst); add(usrNameFeild, txtCnst); comp.setFont(getFont().deriveFont(Font.BOLD, 13)); new Color[] { new Color(0x002AFF), new Color(0x0CAAF9), new Color(0x0CAAF9), new Color(0x002AFF) }); JFrame frame = new JFrame("Demo: LogIn Dialogue"); frame.setSize(new Dimension(500, 300)); MainContainer container = new MainContainer(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true);
public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) { g = (Graphics2D)g.create(); g.translate(xDistance, yDistance); g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), Math.round(opacity * 255))); g.fill(glyph.getShape()); // Also shadow the outline, if one exists. for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();) { Effect effect = (Effect)iter.next(); if (effect instanceof OutlineEffect) { Composite composite = g.getComposite(); g.setComposite(AlphaComposite.Src); // Prevent shadow and outline shadow alpha from combining. g.setStroke(((OutlineEffect)effect).getStroke()); g.draw(glyph.getShape()); g.setComposite(composite); break; } } g.dispose(); if (blurKernelSize > 1 && blurKernelSize < NUM_KERNELS && blurPasses > 0) blur(image); }
private int padding = 25; private int labelPadding = 25; private Color lineColor = new Color(44, 102, 230, 180); private Color pointColor = new Color(100, 100, 100, 180); private Color gridColor = new Color(200, 200, 200, 200); private static final Stroke GRAPH_STROKE = new BasicStroke(2f); private int pointWidth = 4; super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); double xScale = ((double) getWidth() - (2 * padding) - labelPadding) / (scores.size() - 1); double yScale = ((double) getHeight() - 2 * padding - labelPadding) / (getMaxScore() - getMinScore()); g2.setColor(Color.WHITE); g2.fillRect(padding + labelPadding, padding, getWidth() - (2 * padding) - labelPadding, getHeight() - 2 * padding - labelPadding); g2.setColor(Color.BLACK); g2.drawString(yLabel, x0 - labelWidth - 5, y0 + (metrics.getHeight() / 2) - 3); g2.drawString(xLabel, x0 - labelWidth / 2, y0 + metrics.getHeight() + 3); invalidate(); this.repaint();
+ "The effect we want is a multi-line label."; JFrame f = new JFrame("Label Render Test"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); textLabel.setSize(textLabel.getPreferredSize()); Dimension d = textLabel.getPreferredSize(); BufferedImage bi = new BufferedImage( d.width, BufferedImage.TYPE_INT_ARGB); Graphics g = bi.createGraphics(); g.setColor(new Color(255, 255, 255, 128)); g.fillRoundRect( 0, 0, JLabel imageLabel = new JLabel(ii); f.getContentPane().add(imageLabel); f.pack(); f.setLocationByPlatform(true); f.setVisible(true);
private static final int BORDER_GAP = 30; private static final Color GRAPH_COLOR = Color.green; private static final Color GRAPH_POINT_COLOR = new Color(150, 50, 50, 180); private static final Stroke GRAPH_STROKE = new BasicStroke(3f); private static final int GRAPH_POINT_WIDTH = 12; super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); double xScale = ((double) getWidth() - 2 * BORDER_GAP) / (scores.size() - 1); double yScale = ((double) getHeight() - 2 * BORDER_GAP) / (MAX_SCORE - 1); g2.drawLine(BORDER_GAP, getHeight() - BORDER_GAP, BORDER_GAP, BORDER_GAP); g2.drawLine(BORDER_GAP, getHeight() - BORDER_GAP, getWidth() - BORDER_GAP, getHeight() - BORDER_GAP); int y0 = getHeight() - (((i + 1) * (getHeight() - BORDER_GAP * 2)) / Y_HATCH_CNT + BORDER_GAP); int y1 = y0; g2.drawLine(x0, y0, x1, y1); Stroke oldStroke = g2.getStroke(); g2.setColor(GRAPH_COLOR); g2.setStroke(GRAPH_STROKE); for (int i = 0; i < graphPoints.size() - 1; i++) { int x1 = graphPoints.get(i).x;
private void renderPoly(Graphics2D graphics, Color color, Polygon polygon) { if (polygon != null) { graphics.setColor(color); graphics.setStroke(new BasicStroke(2)); graphics.draw(polygon); graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 20)); graphics.fill(polygon); } } }
this.setPreferredSize(new Dimension(W, H)); timer.start(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setBackground(new Color(0f, 0f, 0f, 0.3f)); f.setUndecorated(true); f.add(new Translucent()); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); public void actionPerformed(ActionEvent e) { now.setTime(System.currentTimeMillis()); this.repaint();
private void drawTextInImg(BufferedImage baseImage, String textToWrite, int x, int y) { Graphics2D g2D = (Graphics2D) baseImage.getGraphics(); g2D.setColor(new Color(167, 136, 69)); //TODO 注意,这里的ĺ—体必须安装在服务器上 g2D.setFont(new Font("Microsoft YaHei", Font.PLAIN, 28)); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.drawString(textToWrite, x, y); g2D.dispose(); }
final BufferedImage dietered = floydSteinbergDithering(ImageIO.read(new URL("http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png"))).getSubimage(100, 100, 300, 300); JFrame frame = new JFrame("Test"); frame.setLayout(new GridLayout(1, 2)); frame.add(new JComponent() { @Override protected void paintComponent(Graphics g) { Color color = new Color(c); this.r = color.getRed(); this.g = color.getGreen(); this.b = color.getBlue(); return new Color(clamp(r), clamp(g), clamp(b));
constraints.fill = GridBagConstraints.BOTH; JLabel l = new JLabel("You have got 2 new Messages."); panel.add(l, constraints); constraints.gridx++; constraints.weightx = 0f; dialog.dispose(); new float[]{0f, 0.3f, 1f}, new Color[]{new Color(0.8f, 0.8f, 1f), new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f)}); dialog.setContentPane(panel); dialog.setVisible(true); setOpaque(true); protected void paintComponent(final Graphics g) { final Graphics2D g2d = (Graphics2D) g; g2d.setPaint(lpg); g2d.fillRect(1, 1, getWidth() - 2, getHeight() - 2); g2d.setColor(Color.BLACK); g2d.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
repaint(); repaint(); super.paintComponent(g); for (Line line : lines) { g.setColor(line.color); g.drawLine(line.x1, line.y1, line.x2, line.y2); int y1 = (int) (Math.random()*200); int y2 = (int) (Math.random()*200); Color randomColor = new Color((float)Math.random(), (float)Math.random(), (float)Math.random()); comp.addLine(x1, y1, x2, y2, randomColor); testFrame.pack(); testFrame.setVisible(true);
"<div style='width: 100%; height: 100%; " + "background-color: #" + Integer.toHexString(color.getRed()) + Integer.toHexString(color.getGreen()) + Integer.toHexString(color.getBlue()) + ";'>" + value.toString() + ta.setFocusable(false); return ta; JPanel fontTable = new JPanel(new BorderLayout(3, 1)); fontTable.setFocusable(true); JPanel fontNameCol = new JPanel(new GridLayout(0, 1, 2, 2)); JPanel fontExampleCol = new JPanel(new GridLayout(0, 1, 2, 2)); fontTable.add(fontNameCol, BorderLayout.WEST); fontTable.add(fontExampleCol, BorderLayout.CENTER); for (int ii = 0; ii < fonts.length; ii++) { fontNameCol.add(new JLabel(fonts[ii]));
protected void paintComponent(Graphics g) { if (getModel().isPressed()) { g.setColor(pressedBackgroundColor); } else if (getModel().isRollover()) { g.setColor(hoverBackgroundColor); } else { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); super.paintComponent(g); JFrame frame = new JFrame("Test button"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final MyButton btnSave = new MyButton("Save"); btnSave.setForeground(new Color(0, 135, 200).brighter()); btnSave.setHorizontalTextPosition(SwingConstants.CENTER); btnSave.setBorder(null); btnSave.setBackground(new Color(3, 59, 90)); btnSave.setHoverBackgroundColor(new Color(3, 59, 90).brighter()); btnSave.setPressedBackgroundColor(Color.PINK); frame.add(btnSave); frame.setSize(200, 200); frame.setVisible(true);
JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jtp.setPreferredSize(new Dimension(400, 200)); createTab("Reds", Color.RED); createTab("Greens", Color.GREEN); createTab("Blues", Color.BLUE); f.add(jtp, BorderLayout.CENTER); f.pack(); f.setVisible(true); this.parent = parent; this.icon = icon; this.mask = icon.color.getRGB(); this.setBackground(icon.color); label.setForeground(icon.color); this.add(label); timer.start(); this.setBackground(new Color(rnd.nextInt() & mask)); this.icon.update(count += rnd.nextInt(8)); this.parent.repaint(); g.setColor(color); g.fillRect(x, y, w, H);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setLocationByPlatform(true); window.setVisible(true); private Color pInterfaceColour = new Color(255, 245, 62); protected int iDegreeWhite = 180; protected int iDegreeBlack = 0; setSize(iWidth, iHeight); getContentPane().setBackground(pInterfaceColour); pGradientPane = new JPanel() { private static final long serialVersionUID = 1L; pGraphicsGradientRender.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); GradientPaint pGradient = new GradientPaint(0, 0, new Color(255, 255, 255, iDegreeWhite), 0, getHeight(), new Color(0, 0, 0, iDegreeBlack)); pGraphicsGradientRender.setPaint(pGradient); pGraphicsGradientRender.fillRect(0, 0, getWidth(), getHeight()); super.paintComponent(pGraphics); pGradientPane.setPreferredSize(new Dimension(iWidth - 16, iHeight - 62)); add(pGradientPane);