/* * Skytils - Hypixel Skyblock Quality of Life Mod * Copyright (C) 2021 Skytils * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package swing; import javax.swing.*; import java.awt.*; public class RoundedRectanglePanel extends JPanel { private final int rw; private final int rh; public RoundedRectanglePanel(int radiusW, int radiusH) { super(); this.rw = radiusW; this.rh = radiusH; } @Override protected void paintComponent(Graphics g) { Dimension arcs = new Dimension(rw,rh); //Border corners arcs {width,height}, change this to whatever you want int width = getPreferredSize().width; int height = getPreferredSize().height; Graphics2D graphics = (Graphics2D) g; graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //Draws the rounded panel with borders. graphics.setColor(getBackground()); graphics.fillRoundRect(0, 0, width - 1, height - 1, arcs.width, arcs.height);//paint background graphics.setColor(getForeground()); graphics.drawRoundRect(0, 0, width - 1, height - 1, arcs.width, arcs.height);//paint border } }