Solved

How to set line width using Graphics.drawRect?

Posted on 2000-04-06
4
983 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
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
runtime exception 2 41
throw exception 21 58
Java string replace 11 54
Setup GlassFish 4 21
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

809 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