What is Graphics.draw3DRect() method? – Queslers

What is Graphics.draw3DRect() method? Answer


In this shot, we’ll learn about the draw3DRect() method that draws a 3D highlighted outline of the rectangle with specified parameters.

This method is provided by the Graphics class present in the java.awt package.


draw3DRect(x, y, width, height, boolean)


The method accepts the following parameters:

  • x: The x coordinate of the rectangle.
  • y: The y coordinate of the rectangle.
  • width: The width of the rectangle.
  • height: The height of the rectangle.
  • boolean: Determines whether the rectangle to be drawn appears above the surface or sunk into the surface.


Let’s take a look at an example:

//import required packages
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel {

  public void paint(Graphics g) {

    //set color to graphics object
    g.setColor (Color.gray);

    //draw raised rectangle
    g.draw3DRect (25, 10, 50, 75, true);

    //draw sinked rectangle
    g.draw3DRect (25, 110, 50, 75, false);

  public static void main(String[] args) {
    //Instantiate JFrame
    JFrame frame = new JFrame();

    //add panel
    frame.getContentPane().add(new Main());

    //Will exit the program when you close the gui

    //set width and height of the frame
    frame.setSize(400, 400);

    //set visibility of the frame


In the above code:

  • Line 12: We set the graphics color so that the rectangle borders take the present color.
  • Line 15: We draw a raised rectangle with width 50, height 75, and 25 as x coordinate and 10 as y coordinate.
  • Line 18: We draw a sunk rectangle.
What is Graphics.draw3DRect() method? Review:

In our experience, we suggest you solve this What is Graphics.draw3DRect() method? and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the What is Graphics.draw3DRect() method?

Find on Educative


I hope this What is Graphics.draw3DRect() method? would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published.