Here you can find the source of drawRoundedRect(Graphics g, int left, int top, int right, int bottom)
public static void drawRoundedRect(Graphics g, int left, int top, int right, int bottom)
//package com.java2s; /*//www .j a va 2s. c o m * ?Copyright (C) 2013 Atlas of Living Australia * All Rights Reserved. * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. */ import java.awt.BasicStroke; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Stroke; public class Main { private static final int cornerSize = 2; public static void drawRoundedRect(Graphics g, int left, int top, int right, int bottom) { Graphics2D g2d = (Graphics2D) g; g.drawLine(left + cornerSize, top, right - cornerSize, top); g.drawLine(left + cornerSize, bottom, right - cornerSize, bottom); g.drawLine(left, top + cornerSize, left, bottom - cornerSize); g.drawLine(right, top + cornerSize, right, bottom - cornerSize); final Object previousAntiAliasingHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING); final Stroke previousStroke = g2d.getStroke(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); try { g.drawLine(left, top + cornerSize, left + cornerSize, top); g.drawLine(left, bottom - cornerSize, left + cornerSize, bottom); g.drawLine(right, top + cornerSize, right - cornerSize, top); g.drawLine(right, bottom - cornerSize, right - cornerSize, bottom); } finally { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, previousAntiAliasingHint); g2d.setStroke(previousStroke); } } }