Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do you mean something like this:</p> <p><img src="https://i.stack.imgur.com/INVxl.png" alt="enter image description here"></p> <pre><code>import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.RenderingHints; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class ShadowTest { private JFrame frame; public ShadowTest() { initComponents(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new ShadowTest(); } }); } private void initComponents() { frame = new JFrame(); frame.setTitle("Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//app exited when frame closes frame.setResizable(false); frame.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.fill = GridBagConstraints.HORIZONTAL; gc.insets = new Insets(10, 10, 10, 10); frame.add(new RoundedPanel(), gc); //pack frame (size components to preferred size) frame.pack(); frame.setVisible(true);//make frame visible } } class RoundedPanel extends JPanel { /** * Stroke size. it is recommended to set it to 1 for better view */ protected int strokeSize = 1; /** * Color of shadow */ protected Color shadowColor = Color.black; /** * Sets if it drops shadow */ protected boolean shady = true; /** * Sets if it has an High Quality view */ protected boolean highQuality = true; /** * Double values for Horizontal and Vertical radius of corner arcs */ protected Dimension arcs = new Dimension(0, 0); //protected Dimension arcs = new Dimension(20, 20);//creates curved borders and panel /** * Distance between shadow border and opaque panel border */ protected int shadowGap = 10; /** * The offset of shadow. */ protected int shadowOffset = 4; /** * The transparency value of shadow. ( 0 - 255) */ protected int shadowAlpha = 150; int width = 300, height = 300; public RoundedPanel() { super(); setOpaque(false); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Color shadowColorA = new Color(shadowColor.getRed(), shadowColor.getGreen(), shadowColor.getBlue(), shadowAlpha); Graphics2D graphics = (Graphics2D) g; //Sets antialiasing if HQ. if (highQuality) { graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } //Draws shadow borders if any. if (shady) { graphics.setColor(shadowColorA); graphics.fillRoundRect( shadowOffset,// X position shadowOffset,// Y position width - strokeSize - shadowOffset, // width height - strokeSize - shadowOffset, // height arcs.width, arcs.height);// arc Dimension } else { shadowGap = 1; } //Draws the rounded opaque panel with borders. graphics.setColor(getBackground()); graphics.fillRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height); graphics.setColor(getForeground()); graphics.setStroke(new BasicStroke(strokeSize)); graphics.drawRoundRect(0, 0, width - shadowGap, height - shadowGap, arcs.width, arcs.height); //Sets strokes to default, is better. } @Override public Dimension getPreferredSize() { return new Dimension(width, height); } } </code></pre> <p><strong>Reference:</strong></p> <ul> <li><a href="http://www.codeproject.com/Articles/114959/Rounded-Border-JPanel-JPanel-graphics-improvements" rel="nofollow noreferrer">Rounded Border <code>JPanel</code></a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload