Solved

How to set line width using Graphics.drawRect?

Posted on 2000-04-06
4
1,014 Views
Last Modified: 2008-02-01
im using Graphics.drawRect to draw some rects. how can i adjust the line width ?

Thanks,
  P
0
Comment
Question by:pipe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Expert Comment

by:Daman
ID: 2692085
after
void drawRect(int top, int left, int width, int height)
call
fillRect(int top, int left, int width, int height

eg,
if you want to have rect(100*50) of width 5

call

c1.drawRect(10, 10, 100, 50)
c2.fillRect(10, 10, 100, 50)
c1.fillRect(15, 15, 90, 40)

(where c1 and c2 are "black" and "red" color)


This will work for you.
0
 
LVL 4

Expert Comment

by:jerch
ID: 2692133
Hi pipe...
Do you mean the thickness of the line? I don't think you can set it.  You can do this instead.

        int thickNess = 4;
        for (int i = 0; i < thickNess; i++)
            g.drawRect(x + i, y + i, width - 2 * i, height - 2 * i);

regards..
Jerson
0
 
LVL 2

Accepted Solution

by:
stalefish earned 100 total points
ID: 2692226
Actually, if you use Graphics2D, you can adjust the thickness

public void paint(Graphics g){
  BasicStroke stroke = new BasicStroke(5); //5 pixels wide
  Graphics2D g2 = (Graphics2D) g;
  g2.setStroke(stroke);
  g2.drawRect(w,x,y,z);
  ...
}
0
 

Expert Comment

by:aniket040700
ID: 2693073
the possible option is using drawRect() for straight lines only.

public void paint(Graphics g)
{
   g.drawRect(int a, int b, widht w, height h);
}

a and b are the co-ordinates

w is the length of the line

h is the thickness
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
check java version using powershell 13 298
Problem to Alipay 10 71
What browser will run Java? 7 127
What is the use of Forwarding Class in java 1 37
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question